Number.isSafeInteger()

Determines whether a value is an integer that can be exactly represented as a double.

Since ES2015 Spec ↗

Syntax

Number.isSafeInteger(value)

Parameters

NameTypeRequiredDescription
value any Yes The value to test.

Returns

boolean — true if the value is a safe integer; otherwise false.

Examples

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

Notes

A safe integer is one between -(2^53 - 1) and 2^53 - 1 inclusive, where no other integer rounds to it. Use BigInt for integers beyond this range.

Browser & runtime support

EnvironmentSince version
chrome 34
firefox 32
safari 10
edge 12
node 0.12

See also