JavaScript – Numbers

JavaScript has only one type of number.
JavaScript numbers are always stored as double precision floating point numbers (64 bits).
JavaScript does not define different types of numbers, like integers, short, long, floating-point etc.

Example

<script>
var pi=3.14;    // A number written with decimals
var x=34;       // A number written without decimals

var y=123e5;    // 12300000 scientific exponent notation
var z=123e-5;   // 0.00123  scientific exponent notation

// Floating point arithmetic is not always 100% accurate
var x = 0.2+0.1; // precision: result will be 0.30000000000000004 

var y = 0377;    // Octal       - with a leading zero in octal
var z = 0xFF;    // Hexadecimal

// Conversion
var myNumber = 128;
document.write(myNumber + ' decimal<br>');             // result 128 decimal
document.write(myNumber.toString(16) + ' hex<br>');    // result 80 hex
document.write(myNumber.toString(8) + ' octal<br>');   // result 200 octal
document.write(myNumber.toString(2) + ' binary<br>');  // result 10000000 binary

var x = 2/0;     // result Infinity

// NaN - Not a Number
var x = 1000 / "Apple";
isNaN(x); // returns true

var y = 100 / "1000";
isNaN(y); // returns false

var x = 1000 / 0;
isNaN(x); // returns false because Infinity is a number

</script>

Infinity
If you calculate a number outside the largest number provided by Javascript, Javascript will return the value of Infinity.
Division by 0 (zero) also generates Infinity:

My official WebSite >