JS: Number.MIN_SAFE_INTEGER, MAX_SAFE_INTEGER

By Xah Lee. Date: .

MIN_SAFE_INTEGER

Number.MIN_SAFE_INTEGER

Value is -9007199254740991 (same as -(2^53-1)).

It's the smallest integer n such that n and n - 1 are both exactly representable as a Number value.

console.assert(Number.MIN_SAFE_INTEGER === -9007199254740991);
console.assert(Number.MIN_SAFE_INTEGER === -(2 ** 53 - 1));

MAX_SAFE_INTEGER

Number.MAX_SAFE_INTEGER

Value is 9007199254740991. Same as (2^53 - 1).

It's the largest integer n such that n and n + 1 are both exactly representable as a Number value.

console.assert(Number.MAX_SAFE_INTEGER === 9007199254740991);
// beyond, you have problems

console.assert(
 Number.MAX_SAFE_INTEGER + 1 ===
  Number.MAX_SAFE_INTEGER + 2,
);

JavaScript number special values