Skip to content
Related Articles

Related Articles

Underscore.js _.isZero() Method

Improve Article
Save Article
Like Article
  • Last Updated : 31 Jul, 2020

The _.isZero() Method checks whether the given value is a Zero value or not, correspondingly returning a boolean value. 

Syntax:

_.isZero(value);

Parameters:  This method accepts a single parameter as mentioned above and described below:

  • value: Given value to be checked for Zero value.

Return Value: This method returns a Boolean value(Returns true if the given value is Zero, else false).

Note: This will not work in normal JavaScript because it requires the underscore.js contrib library to be installed. 

underscore.js contrib library can be installed using npm install underscore-contrib –save.

Example 1:

Javascript




// Defining underscore contrib variable
var _ = require('underscore-contrib'); 
// Checking
console.log("The Value is Zero : " +_.isZero(0));

Output:

The Value is Zero : true

Example 2:

Javascript




// Defining underscore contrib variable
var _ = require('underscore-contrib'); 
// Checking
console.log("The Value is Zero : " +_.isZero(10));

Output:

The Value is Zero : false

Example 3: For string containing zero this returns false

Javascript




// Defining underscore contrib variable
var _ = require('underscore-contrib'); 
// Checking
console.log("The Value is Zero : " +_.isZero("0"));

Output:

The Value is Zero : false

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!