Open In App

Underscore.js _.isZero() Method

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:

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:




// 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:




// 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




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

Output:

The Value is Zero : false

Article Tags :