Course contentsShow
← JavaScript
Lesson 118 of 2,7234. Working with NumbersFree lesson

Number.MAX_SAFE_INTEGER and MIN_SAFE_INTEGER

Discover the range of integers that can be represented exactly without losing precision.

Number.MAX_SAFE_INTEGER and MIN_SAFE_INTEGER

What you'll learn: The exact boundaries of integers that JavaScript can represent without losing precision.

The Safe Integer Range

JavaScript uses 64-bit floating-point numbers for all numeric values. While this allows for a huge range of numbers, it doesn't mean every integer can be represented exactly. Due to how floating-point storage works, there's a specific range where integers are guaranteed to be precise.

Number.MAX_SAFE_INTEGER is the largest integer JavaScript can represent with absolute precision: 9,007,199,254,740,991 (about 9 quadrillion).

Number.MIN_SAFE_INTEGER is the smallest: -9,007,199,254,740,991 (the negative equivalent).

Beyond these boundaries, JavaScript starts "skipping" integers—consecutive whole numbers no longer exist. Arithmetic becomes unreliable.

Why This Matters

console.log(Number.MAX_SAFE_INTEGER);     // 9007199254740991
console.log(Number.MIN_SAFE_INTEGER);     // -9007199254740991

// Within safe range - works perfectly
console.log(9007199254740991 + 1);        // 9007199254740992 ✓

// Beyond safe range - precision lost
console.log(9007199254740992 + 1);        // 9007199254740992 ✗
console.log(9007199254740993 === 9007199254740992);  // true ✗

Once you exceed MAX_SAFE_INTEGER, adding 1 might not change the value at all! The numbers become too large to distinguish from each other.

Analogy

Think of safe integers like a ruler with precise markings. Within the safe range, every millimeter is clearly marked. Beyond it, the markings start spreading out—you can't tell if something is 100cm or 100.5cm anymore.

Key Takeaway: Use Number.MAX_SAFE_INTEGER and Number.MIN_SAFE_INTEGER to understand JavaScript's precision limits—outside this range (±9 quadrillion), integer arithmetic becomes unreliable. For larger integers, use BigInt instead.