The Number.isSafeInteger() method determines whether a value is a safe integer.
The Number.isSafeInteger() method determines whether a value is a safe integer.
A safe integer is an integer that can be represented as an IEEE-754 double precision number (all integers from (2^53 - 1) to -(2^53 - 1))
Number.isSafeInteger(value)
Parameter | Require | Description |
---|---|---|
value | Required. | The value to be tested |
A Boolean. Returns true if the value is a safe integer Number, otherwise it returns false
Check whether a value is a safe integer:
var res = ""; res = res + Number.isSafeInteger(123) + ": 123\n"; res = res + Number.isSafeInteger(-123) + ": -123\n"; res = res + Number.isSafeInteger(5-2) + ": 5-2\n"; res = res + Number.isSafeInteger(0) + ": 0\n"; res = res + Number.isSafeInteger(null) + ": null\n"; res = res + Number.isSafeInteger(0.5) + ": 0.5\n"; res = res + Number.isSafeInteger(Math.pow(2, 53)) + ": 2<sup>53</sup>\n"; res = res + Number.isSafeInteger(Math.pow(2, 53) - 1) + ": 2<sup>53</sup> - 1\n"; res = res + Number.isSafeInteger('123') + ": '123'\n"; res = res + Number.isSafeInteger(false) + ": false\n"; res = res + Number.isSafeInteger(Infinity) + ": Infinity\n"; res = res + Number.isSafeInteger(-Infinity) + ": -Infinity\n"; res = res + Number.isSafeInteger(0 / 0) + ": 0 / 0\n"; console.log(res);// w w w . ja v a 2 s . co m