Understanding Numbers in JavaScript
There are two types of numbers in JavaScript:
- Safe Integers, limited by 53 bits
- BigIntegers, unlimited
Let’s talk about regular numbers first.
In Javascript regular numbers are stored as 64-bit floating point numbers, following the IEEE 754
standard.
They are limited by the precision of the floating point representation, which is 53 bits.
Here is the format of the 64-bit floating point number:
- Fraction: 52 bits (0 - 51). Effective integer precision is 53 bits, hence
Number.MAX_SAFE_INTEGER
is2^53 - 1 = 9007199254740991
. - Exponent: 11 bits (52 - 62)
- Sign: 1 bit (63)