JS: Number . MIN_SAFE_INTEGER, MAX_SAFE_INTEGER

By Xah Lee. Date: . Last updated: .

Max safe integer

Number.MAX_SAFE_INTEGER

Value is the largest integer n such that n and n + 1 are both exactly representable as a Number value.

console.log(Number. MAX_SAFE_INTEGER. toLocaleString());
// 9,007,199,254,740,991
// beyond, you have problems

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

Min safe integer

Number.MIN_SAFE_INTEGER

Value is the smallest integer n such that n and n - 1 are both exactly representable as a Number value.

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

console.log(Number.MIN_SAFE_INTEGER.toLocaleString());
// -9,007,199,254,740,991

console.log((-(2 ** 53 - 1)).toLocaleString());
// -9,007,199,254,740,991

JavaScript number special values