Lodash _.isSafeInteger() Method
Last Updated :
03 Nov, 2023
Lodash _.isSafeInteger() method is used to find whether the given value is a safe integer or not. It returns True if the given value is a safe integer. Otherwise, it returns false. An integer is safe if it’s an IEEE-754 double-precision number(all integers from (2 53 – 1) to -(2 53 – 1)) which isn’t the result of a rounded unsafe integer.
Syntax:
_.isSafeInteger(value);
Parameters:
- value: This parameter holds the value to check.
Return Value:
This method returns true if the value is a safe integer, else false.
Example 1: In this example, we are checking whether the given value is a safe integer or not.
javascript
const _ = require( 'lodash' );
console.log(_.isSafeInteger(Math.pow(2, 53) - 1));
console.log(_.isSafeInteger(Infinity));
console.log(_.isSafeInteger(Number.MIN_VALUE));
|
Output:
true
false
false
Example 2: In this example, we are checking whether the given value is a safe integer or not.
javascript
const _ = require( 'lodash' );
console.log(_.isSafeInteger(123));
console.log(_.isSafeInteger(-123));
console.log(_.isSafeInteger(0.123));
|
Output:
true
true
false
Note: This code will not work in normal JavaScript because it requires the library lodash to be installed.
Reference: https://lodash.com/docs/4.17.15#isSafeInteger
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...