Latest web development tutorials
 

JavaScript Number isSafeInteger() Method

< JavaScript Number Reference

Example

Check whether a value is an safe integer:

Number.isSafeInteger(123) //true
Number.isSafeInteger(-123) //true
Number.isSafeInteger(5-2) //true
Number.isSafeInteger(0) //true
Number.isSafeInteger(0.5) //false
Number.isSafeInteger(Math.pow(2, 53)) //false
Number.isSafeInteger(Math.pow(2, 53) - 1) //true
Number.isSafeInteger('123') //false
Number.isSafeInteger(false) //false
Number.isSafeInteger(Infinity) //false
Number.isSafeInteger(-Infinity) //false
Number.isSafeInteger(0 / 0) //false
Try it Yourself »

Definition and Usage

The Number.isSafeInteger() method determines whether a value a 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))

This method returns true if the value is of the type Number, and a safe integer. Otherwise it returns false.


Browser Support

Method
Number.isSafeInteger() 19 12.0 32 9 22

Syntax

Number.isSafeInteger(value)

Parameter Values

Parameter Description
value Required. The value to be tested

Technical Details

Return Value: A Boolean. Returns true if the value is a safe integer Number, otherwise it returns false
JavaScript Version: ECMAScript 6

< JavaScript Number Reference