ABOUT CONTACT
Prev Page Next Page
Top

JavaScript Numbers

➢JavaScript has only one type of number. Numbers can be written with or without decimals.

Integer Precision

➢Integers (numbers without a period or exponent notation) are accurate up to 15 digits.
➢The maximum number of decimals is 17.

EXAMPLE:

let x = 99999999999999999; // x will be 999999999999999
let x = 999999999999999999; // y will be 10000000000000000

Floating Precision


EXAMPLE:

let x = 0.2 + 0.1;

NaN - Not a Number

➢NaN is a JavaScript reserved word indicating that a number is not a legal number.

EXAMPLE:

let x = 100 / "Apple";
isNaN(x);

Infinity

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

EXAMPLE:

let x = 100;
// Execute until Infinity;
while (x != Infinity) {
    x = x * x;
}

Hexadecimal

➢JavaScript interprets numeric constants as hexadecimal if they are preceded by 0x.

EXAMPLE:

let x = 0xFF;

Prev Page Next Page