SKU // 35

JavaScript Number Properties

The built-in Number object holds a set of fixed values, called properties, that describe the limits of what JavaScript numbers can do. You read them straight off Number itself, like Number.MAX_VALUE. Knowing these limits explains a lot of "impossible" bugs.

Number.MAX_SAFE_INTEGERLargest exact whole number
Number.MIN_SAFE_INTEGERMost negative exact whole number
Number.MAX_VALUELargest number of any kind
Number.MIN_VALUESmallest number above zero
Number.POSITIVE_INFINITYInfinity
Number.NEGATIVE_INFINITY-Infinity
Number.EPSILONTolerance for comparing decimals
Number.NaNNot a Number

// The Safe Integer Range

JavaScript can store whole numbers exactly only up to a certain size. That size is 253 - 1, available as Number.MAX_SAFE_INTEGER (both safe-integer properties were added in ES6):

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

That is about 9 quadrillion. Past it, whole numbers start losing accuracy:

let max = Number.MAX_SAFE_INTEGER;
console.log(max + 1);
console.log(max + 2);                // wrong! should end in 3
console.log(max + 1 === max + 2);    // two different numbers, "equal"
9007199254740992 9007199254740992 true

Check whether a value is still in the safe zone with Number.isSafeInteger():

console.log(Number.isSafeInteger(9007199254740991));
console.log(Number.isSafeInteger(9007199254740992));
true false
Note
This matters for things like database IDs from very large systems, which can exceed the safe range. Such IDs are often sent as strings for exactly this reason. For true big-number math, see JS BigInt.

// Largest and Smallest Values

console.log(Number.MAX_VALUE);    // largest possible number
console.log(Number.MIN_VALUE);    // smallest number above zero
1.7976931348623157e+308 5e-324

MAX_VALUE is far bigger than MAX_SAFE_INTEGER: JavaScript can hold numbers that large, just not exactly. e+308 means "times 10 to the power of 308": a number 309 digits long.

Watch out: MIN_VALUE is not the most negative number
Despite the name, MIN_VALUE is the tiniest positive number: the closest you can get to zero without being zero. (Some tutorials, including W3Schools, describe it as "the lowest possible number", which is wrong.) The most negative number is -Number.MAX_VALUE.

// Infinity

console.log(Number.POSITIVE_INFINITY);
console.log(Number.NEGATIVE_INFINITY);
console.log(1 / 0);                      // what dividing by zero gives
console.log(Number.MAX_VALUE * 2);       // overflow
Infinity -Infinity Infinity Infinity

Use Number.isFinite() to reject both infinities and NaN in one check:

console.log(Number.isFinite(100));
console.log(Number.isFinite(1 / 0));
console.log(Number.isFinite(NaN));
true false false
Tip
Number.isFinite(x) is a great one-line check that a calculation produced a real, usable number.

// NaN

Number.NaN is the same value as the global NaN: a reserved word for "not a legal number". You get it from arithmetic with a non-numeric string:

console.log(Number.NaN);
console.log(100 / "Apple");
NaN NaN

// EPSILON: Comparing Decimals Safely

Number.EPSILON (ES6) is the difference between 1 and the smallest number greater than 1 that JavaScript can store: about 0.0000000000000002. It helps compare decimals that should be equal but are off by a rounding hair:

let a = 0.1 + 0.2;
let b = 0.3;
console.log(a === b);
console.log(Math.abs(a - b) < Number.EPSILON);    // "close enough"
false true

Math.abs() gives the distance between the two numbers, ignoring which is bigger. If that distance is smaller than EPSILON, treat them as equal.

// Properties Belong to Number, Not Your Variable

These properties only exist on Number itself. Reading one off a variable or a value gives undefined, with no error:

let x = 6;
console.log(x.MAX_VALUE);
console.log(Number.MAX_VALUE);
undefined 1.7976931348623157e+308

// Quick Check

Which is the most negative number JavaScript can store?

  1. Number.MIN_VALUE
  2. Number.MIN_SAFE_INTEGER
  3. -Number.MAX_VALUE
  4. Number.EPSILON
Show answer
C. MIN_VALUE is the tiniest positive number. MIN_SAFE_INTEGER is the most negative number that is stored exactly, but much more negative numbers exist. (-Infinity is lower still, but it is not a real number.)

What does this log?

let id = 9007199254740993;
console.log(id);
Show answer
9007199254740992. The number is past MAX_SAFE_INTEGER, so it cannot be stored exactly and is rounded to the nearest number that can. That is how a big database ID can silently point to the wrong record.

What does let score = 50; console.log(score.MAX_VALUE); log?

  1. 1.7976931348623157e+308
  2. 50
  3. undefined
  4. A TypeError
Show answer
C. MAX_VALUE only exists on Number. Reading a property that does not exist gives undefined, not an error. Write Number.MAX_VALUE.

// Try It

  1. Click Open Playground. Log max + 1, max + 2, and max + 3. Which results are wrong?
  2. Use Number.isFinite to check the results of 10 / 2, 10 / 0, and "a" / 2
  3. Compare 0.1 + 0.2 to 0.3 using the EPSILON technique
  4. Log Number.MIN_VALUE / 2. What happens when you go below the smallest positive number?
// Video Walkthroughs
Last updated: Oct 10, 2026, 12:51 AM ET