JavaScript numbers are always stored as double precision floating point numbers, following the international IEEE 754 standard.

This format stores numbers in 64 bits, where the number (the fraction) is stored in bits 0 to 51, the exponent in bits 52 to 62, and the sign in bit 63

Integers (numbers without a period or exponent notation) are considered accurate up to 15 digits.

var x = 999999999999999;   // x will be 999999999999999
var y = 9999999999999999;  // y will be 10000000000000000

The maximum number of decimals is 17, but floating point arithmetic is not always 100% accurate:

var x = 0.2 + 0.1;         // x will be 0.30000000000000004

To solve the problem above, it helps to multiply and divide:

var x = (0.2 * 10 + 0.1 * 10) / 10;       // x will be 0.3

You can use the toString() method to output numbers as base 16 (hex), base 8 (octal), or base 2 (binary).

var myNumber = 128;
myNumber.toString(16);     // returns 80
myNumber.toString(8);      // returns 200
myNumber.toString(2);      // returns 10000000
myNumber.toString();       // returns "128"

Infinity (or -Infinity) is the value JavaScript will return if you calculate a number outside the largest possible number.

Division by 0 (zero) also generates Infinity.

Infinity is a number: typeof Infinity returns number.

NaN: Not a Number

NaN is a JavaScript reserved word indicating that a number is not a legal number. You can use the global JavaScript function isNaN() to find out if a value is a number.

Trying to do arithmetic with a non-numeric string will result in NaN (Not a Number). However, if the string contains a numeric value , the result will be a number:

var x = 100 / "Apple";  // x will be NaN (Not a Number)
var x = 100 / "10";     // x will be 10

Watch out for NaN. If you use NaN in a mathematical operation, the result will also be NaN. Or the result might be a concatenation:

var x = NaN;
var y = 5;
var y1 = "5";
var z = x + y;           // z will be NaN
var z1 = x + y1;         // z1 will be NaN5

NaN is a number, and typeof NaN returns number:

typeof NaN;             // returns "number"

Yonggoo Noh

I am interested in Computer science and Mathematics.