JavaScript uses IEEE-754 double-precision numbers, which have roughly 15 digits of decimal precision, but a huge range. In this format, the whole numbers -2^53
through 2^53
can all be reliably represented (this is the precision of the significand of the format). Outside those limits, some whole numbers can be represented but others cannot. E.g., outside that range, there are whole-number gaps.
For instance, double-precision numbers can represent 9,007,199,254,740,992
(2^53
) and 9,007,199,254,740,994
(2^53 + 2
), but not 9,007,199,254,740,993
(2^53 + 1
):
Example console session:
> 9007199254740992
9007199254740992
> 9007199254740992 + 1
9007199254740992
> 9007199254740992 + 2
9007199254740994
Note the second of those. That's not a typo.