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 »
Description
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 since June 2017:
Chrome 51 | Edge 15 | Firefox 54 | Safari 10 | Opera 38 |
May 2016 | Apr 2017 | Jun 2017 | Sep 2016 | Jun 2016 |
Number.isSafeInteger()
is not supported in Internet Explorer.