JavaScript Number isSafeInteger() method

All integers which can be represented as an IEEE-754 double precision number are considered safe integers.

JavaScript Number.isSafeInteger() is used check whether the given number is safe integer or not.

Syntax:

Number.isSafeInteger(number)

Parameters
number: It represents the number on which safe integer check have to be inform.

Returns
It returns true if the specified number is a safe integer otherwise returns false.

Example

<!DOCTYPE html>
<html>
<body>
 
<script>
function testThreadSafe() {
  var result = "";
  result = result + Number.isSafeInteger(453) + ": 453<br>";
  result = result + Number.isSafeInteger(-453) + ": -453<br>";
  result = result + Number.isSafeInteger(53-21) + ": 53-21<br>";
  result = result + Number.isSafeInteger('456') + ": '456'<br>";
  result = result + Number.isSafeInteger(false) + ": false<br>";
  result = result + Number.isSafeInteger(Infinity) + ": Infinity<br>";
 
  document.writeln(result);
}
 
testThreadSafe();
</script>
 
</body>
</html>

Output

true: 453
true: -453
true: 53-21
false: '123'
false: false
false: Infinity
Please Share