JavaScript Number isSafeInteger()
Examples
Are these safe integers?
Number.isSafeInteger(123);
Number.isSafeInteger(-123);
Number.isSafeInteger('123');
Try it Yourself »
Number.isSafeInteger(5-2);
Number.isSafeInteger(0);
Number.isSafeInteger(0.5);
Number.isSafeInteger(0/0);
Try it Yourself »
Definition and Usage
The Number.isSafeInteger()
method returns
true
if a number is a safe integer.
Otherwise it returns false
.
What is a JavaScript Safe Integer?
A safe integer is an integer that can be exactly represented as an IEEE-754 double precision number: all integers from (253 - 1) to -(253 - 1).
Syntax
Number.isSafeInteger(value)
Parameters
Parameter | Description |
value | Required. The value to be tested. |
Return Value
Type | Description |
A boolean | true if the value is a safe integer, otherwise false . |
More Examples
Are these safe integers?
Number.isSafeInteger(Math.pow(2, 53));
Number.isSafeInteger(Math.pow(2, 53) - 1);
Try it Yourself »
Number.isSafeInteger(true);
Number.isSafeInteger(false);
Number.isSafeInteger(Infinity);
Number.isSafeInteger(-Infinity);
Try it Yourself »
Browser Support
Number.isSafeInteger()
is an ECMAScript6 (ES6) feature.
ES6 (JavaScript 2015) is supported in all modern browsers:
Chrome | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes |
Number.isSafeInteger()
is not supported in Internet Explorer 11 (or earlier).