All numbers in JavaScript are internally represented by 64-bit floating point numbers (see ยง4.3.19 of the specification). That means it can exactly represent every integer from 0
up to 9007199254740992
(hex value 0x20000000000000
). Any integers greater than that (or less than it’s negative counterpart) may need to be rounded to the closest approximate value.
Observe:
9007199254740992 === 9007199254740993
> true
However, two numbers that are rounded to sufficiently different approximate values still evaluate to different values when you compare them. For example:
9007199254740992 === 9007199254740994
> false
This is what you’re seeing in the second snippet where you add another F
digit.
Note: The ECMAScript specification now define Number.MAX_SAFE_INTEGER
as a global constant equal to 9007199254740991
.