Number.isSafeInteger
Checks that an integer is within the range where it is stored exactly.
Available since: ES2015
Syntax
Number.isSafeInteger(value)Parameters
| Parameter | Type | Description |
|---|---|---|
| value | any | The 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
falseNotes
Beyond this boundary neighbouring integers become indistinguishable: 2 ** 53 === 2 ** 53 + 1 is true. Use BigInt for large integers.
See also
- Number.MAX_SAFE_INTEGER — The largest integer that is stored without losing precision.
- Number.isInteger — Checks whether a value is an integer.
- BigInt — Integers of any size, without loss of precision.
In the tutorial
- Numbers — Numbers in JavaScript — integers and fractions, rounding, the Math object, toFixed and the special values Infinity and NaN.