Friday, September 5, 2025
HomeLanguagesJavascriptLodash _.isSafeInteger() Method

Lodash _.isSafeInteger() Method

Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc.

The _.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: This method accepts a single parameter as mentioned above and described below:

  • value: This parameter holds the value to check.

Return Value: This method returns true if the value is a safe integer, else false.

Note: Here, const _ = require(‘lodash’) is used to import the lodash library into the file.

Example 1:




// Requiring the lodash library  
const _ = require("lodash");  
       
// Use of _.isSafeInteger() method 
  
// Passing a mathematical pow function as an argument
console.log(_.isSafeInteger(Math.pow(2, 53) - 1)); 
  
// Passing a maximum value of a number as an argument
console.log(_.isSafeInteger(Infinity)); 
  
// Passing a minimum value of a number as an argument
console.log(_.isSafeInteger(Number.MIN_VALUE)); 


Output:

true
false
false

Example 2:  




// Requiring the lodash library  
const _ = require("lodash");  
       
// Use of _.isSafeInteger() method 
  
// Passing a positive number as an argument
console.log(_.isSafeInteger(123)); 
  
// Passing a negative number as an argument
console.log(_.isSafeInteger(-123)); 
  
// Passing a number(with decimals) as an argument
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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6634 POSTS0 COMMENTS
Nicole Veronica
11801 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11863 POSTS0 COMMENTS
Shaida Kate Naidoo
6750 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6701 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS