Underscore.js _.isNull() Function
Last Updated :
14 Jan, 2024
Underscore.js _.isNull() function It is used to find whether the value of the object is null. If an object has a null value then the output will be true otherwise false. We can even perform addition, subtraction, etc operations in this function.
Syntax:
_.isNull(object);
Parameters:
It takes only one argument which is the object that needs to be tested.
Return value:
It returns true if the object has a null value otherwise it returns false.
Passing a number in the _.isNull() function:
The _.isNull() function takes the parameter passed to it and then checks whether the object has a null value or not. In this case, since the value is a defined number "10", so the output is not null. Therefore, the output will be false.
Example: This example shows the Passing of a number in the _.isNull() function.
HTML
<html>
<head>
<script src =
"https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js" >
</script>
</head>
<body>
<script type="text/javascript">
let a=10;
console.log(_.isNull(10));
</script>
</body>
</html>
Output:

Passing "null" to the _.isNull() function:
Since here we have passed "null" so we need not check for the object. We know that the value passed to the _.isNull() function itself has value "null". Therefore, the output will be true.
Example: This example shows the passinf of null to the _.isNull() function.
HTML
<html>
<head>
<script src =
"https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js" >
</script>
</head>
<body>
<script type="text/javascript">
console.log(_.isNull(null));
</script>
</body>
</html>
Output:

Passing undefined" to the _.isNull() function:
The _.isNull() function takes the parameter passed to it which here is "undefined". We know that if anything is undefined, then it's value will be null. And hence, the answer is true.
Example: This example shows the passing of undefined value to the _.isNull() function.
HTML
<html>
<head>
<script src =
"https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js" >
</script>
</head>
<body>
<script type="text/javascript">
console.log(_.isNull(undefined));
</script>
</body>
</html>
Output:

Performing operations on the output of _.isNull() function:
In this first we have directly stored the output of both the above 2 examples (2, 3) in variables a and b, and then we have done an addition operation in both the results. Finally, stored it in the third variable. Since the output of _.isNull() is false when we passed and true when we passed null, therefore false is stored in 'a' variable and true is stored in 'b' variable. Now if we perform addition (+) operation on both the 'a', 'b' variables then we will have true as 'b' is true. Hence 'c' variable will become 1.
Example: This example shows the performance of opertions on the output of _.isNull() function.
HTML
<html>
<head>
<script src =
"https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js" >
</script>
</head>
<body>
<script type="text/javascript">
let a = _.isNull(undefined);
let b = _.isNull(null);
let c = a + b;
console.log(a);
console.log(b);
console.log(c);
</script>
</body>
</html>
Output:

NOTE: These commands will not work in Google console or in firefox as for these additional files need to be added which they didn't have added. So, add the given links to your HTML file and then run them. The links are as follows:
<script type="text/javascript" src =
"https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js">
</script>
Similar Reads
Underscore.js _.isNaN() Function
_.isNaN() function:Â It is used to find whether the value of the object passed is NaN or not.If the object's value is NaN then the output will be true otherwise, it will be false.We can even perform addition, subtraction etc operations in this function. Syntax:Â _.isNaN(object) Parameters:It takes o
3 min read
Underscore.js _.isNumber() Function
Underscore.js _.isNumber() function is used to check whether the given object parameter is a number or not. If the given object is a number then it returns True value otherwise, it returns False. Syntax:_.isNumber( object );Parameters:object: This parameter holds the object element that needs to be
1 min read
Underscore.js _.isSet() Function
Underscore.js is a library in javascript that makes operations on arrays, string, objects much easier and handy. _.isSet() function is used to check whether the given object is javascript set or not. When linking the underscore.js CDN The "_" is attached to the browser as global variable. Syntax: _.
2 min read
Underscore.js _.isMap() Function
Underscore.js is a library in javascript that makes operations on arrays, string, objects much easier and handy. _.isMap() function is used to check whether the given object is javascript Map or not. Note: It is very necessary to link the underscore CDN before going and using underscore functions in
2 min read
Underscore.js _.isString() Function
The _.isString() function is used to check whether the given object element is string or not. Syntax: _.isString( object ) Parameters: This function accepts single parameter as mentioned above and described below: object: It contains the value of object that need to be check whether it is an string
1 min read
Underscore.js _.isSymbol() Function
Underscore.js is a library in javascript that makes operations on arrays, string, objects much easier and handy. _.isSymbol() function is used to check whether the given object is javascript Symbol Object or not. Note: It is very necessary to link the underscore CDN before going and using underscore
2 min read
Underscore.js _.has() Function
Underscore.js _.has() function is used to check whether the given object contains the given key or not. Syntax:Â _.has(object, key);Parameters: object: It contains the object element.key: It contains the key that needs to be checked in the given object.Return Value: It returns a Boolean value True if
1 min read
Underscore.js _.isFinite() Function
The _.isFinite() function is used to check whether the value of the parameter passed is finite or not. If the parameter has an infinite value the output is false otherwise, true. We can even perform any operation like addition, subtraction in this function. Syntax:_.isFinite(object) Parameters:It ta
3 min read
Underscore.js _.isDate() function
Underscore.js is a javascript library that is capable enough to handle arrays, strings, objects, map, set very easily and efficiently. The _.isDate() function in underscore.js is used to tell if the given object is a date object or not. Syntax: _.isDate(object); Parameters: It takes only one paramet
1 min read
Underscore.js _.isEmpty() Function
Underscore.js _.isEmpty() function is used to check whether a list, array, string, object, etc is empty or not. It first finds out the length of the passed argument and then decides. If the length is zero, then the output is true otherwise false. Syntax:Â _.isEmpty(object);Parameters:It takes only on
3 min read