How to useLodash _.isNull() Method in Javascript

Lodash _.isNull() method is used to find whether the value of the object is null. If the value is null then returns true otherwise it returns false.

Syntax:

_.isNull(value);

Example: In this example, we are checking whether the given value is null or not by the use of the _isNull() method.

Javascript




// Requiring the lodash library
const _ = require("lodash");
 
// Use of _.isNull()
// method
let gfg = _.isNull(null);
let gfg1 = _.isNull(void 0);
 
// Printing the output
console.log(gfg);
console.log(gfg1);


Output:

true
false


How to check for null values in JavaScript ?

The null values show the non-appearance of any object value. It is usually set on purpose to indicate that a variable has been declared but not yet assigned any value. This contrasts null from the similar primitive value undefined, which is an unintentional absence of any object value. That is because a variable that has been declared but not assigned any value is undefined, not null.

Below are the approaches:

Table of Content

  • By equality Operator (===)
  • By Object.is() function
  • By the typeof Operator
  • Using Lodash _.isNull() Method

Similar Reads

Approach 1: By equality Operator (===)

By this operator, we will learn how to check for null values in JavaScript by the (===) operator. This operator only passes for null values, not for undefined, false, 0, NaN....

Approach 2: By Object.is() function

...

Approach 3: By the typeof Operator

This function checks whether two objects’ values are equal or not. If they are the same the two object’s values are the same if both values are null....

Approach 4: Using Lodash _.isNull() Method

...

Contact Us