Lodash _.isNaN() Method checks the given value is NaN or not. This method is not the same as the JavaScript isNaN() method which returns true for undefined and other non-number values.
Syntax:
_.isNaN( value )
Parameters:
This method accepts a single parameter as mentioned above and described below:
- value: This parameter holds the value that needs to be checked for NaN.
Return Value:
This method returns a Boolean value (Returns true if the value is NaN, else false).
Example 1: This code uses the Lodash library to check if a value is NaN (Not a Number).
Javascript
const _ = require( 'lodash' );
console.log(_.isNaN(NaN));
|
Output:
true
Example 2: For checking with an empty source this method returns true.
Javascript
const _ = require( 'lodash' );
console.log(_.isNaN( new Number(NaN)));
|
Output:
true
Example 3: This code uses the Lodash library to check if values are NaN (Not a Number).This method also works for arrays.
Javascript
const _ = require( 'lodash' );
console.log(_.isNaN(undefined));
console.log(_.isNaN(10));
|
Output:
false
false
Last Updated :
09 Nov, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...