An integer is a safe integer if:
Note: Any integer that falls in the range
[-(2^53 - 1), 2^53 - 1]
is a safe integer.
We can use the _.isSafeInteger()
method in Lodash to check if a value is a safe integer.
The syntax to check the safe integer is:
_.isSafeInteger(value)
This method accepts the following parameters:
value
: This is the value to be checked.This method returns true
if the value is a safe integer. Otherwise, it returns false
.
Let’s look at an example of the _.isSafeInteger()
method in the code snippet below:
In the HTML tab:
lodash
library.In the JavaScript tab:
isValueASafeInteger()
that accepts a value and checks if it is a safe integer using the _.isSafeInteger()
method, and print the result on the console.isValueASafeInteger()
function for each of the variables declared.RELATED TAGS
CONTRIBUTOR
View all Courses