A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript/lodash-_-issafeinteger-method/ below:

Lodash _.isSafeInteger() Method - GeeksforGeeks

Lodash _.isSafeInteger() Method

Last Updated : 04 Sep, 2024

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: Return Value:

Example 1: In this example, we are checking whether the given value is a safe integer or not.

javascript
// Requiring 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: In this example, we are checking whether the given value is a safe integer or not.

javascript
// Requiring 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.



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4