Lodash _.isNil() method checks if a value is either null or undefined. It returns true for both null and undefined values, and false for all other data types, making it useful for validating missing data.
Syntax
_.isNil(value)Parameters
- value(*) parameter holds the value to check.
Return Value
- This method returns true if the value is nullish, else false.
Example 1: In this example, null is null itself so it is returning true.
// Requiring the lodash library
const _ = require("lodash");
// Use of _.isNil()
// method
let gfg = _.isNil(null);
// Printing the output
console.log(gfg);
Output:
trueExample 2: In this example, void is null so it is returning the true value.
// Requiring the lodash library
const _ = require("lodash");
// Use of _.isNil()
// method
let gfg = _.isNil(void 0);
// Printing the output
console.log(gfg);
Output:
trueExample 3: In this example, NaN is not null so it is giving us a false value.
// Requiring the lodash library
const _ = require("lodash");
// Use of _.isNil()
// method
let gfg = _.isNil(NaN);
// Printing the output
console.log(gfg);
Output:
false