Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

Number.isSafeInteger

Checks that an integer is within the range where it is stored exactly.

Available since: ES2015

Syntax

Number.isSafeInteger(value)

Parameters

ParameterTypeDescription
valueanyThe value to check.

Return value

booleantrue if the value is an integer that is stored exactly.

Examples

The boundary of safe integers:

console.log(Number.isSafeInteger(2 ** 53 - 1));
console.log(Number.isSafeInteger(2 ** 53));

Output:

true
false

Notes

Beyond this boundary neighbouring integers become indistinguishable: 2 ** 53 === 2 ** 53 + 1 is true. Use BigInt for large integers.

See also

In the tutorial

  • Numbers — Numbers in JavaScript — integers and fractions, rounding, the Math object, toFixed and the special values Infinity and NaN.

Thanks for reading!

Donate to the site — we work hard for you.