Advertisement
Intermediate JavaScript, Numbers, Math & BigInt

What is Number.MAX_SAFE_INTEGER and what breaks beyond it?

Short answer

It's 2^53 - 1 (9007199254740991), the largest integer JavaScript's double-precision Number type can represent without losing precision. Beyond it, integers can silently round to a nearby representable value, causing incorrect arithmetic and equality checks.

Save JavaScript mock interview
Advertisement
AModel answer
It's 2^53 - 1 (9007199254740991), the largest integer JavaScript's double-precision Number type can represent without losing precision. Beyond it, integers can silently round to a nearby representable value, causing incorrect arithmetic and equality checks.
console.log(Number.MAX_SAFE_INTEGER);           // 9007199254740991
console.log(9007199254740992 === 9007199254740993); // true! precision lost
Real-world example
A bug where large database IDs (like 64-bit Snowflake IDs) get silently corrupted when passed through JavaScript as regular numbers.
Likely follow-ups
  • How does BigInt solve this precision problem?
Related topics