Open In App

Underscore.js _.isZero() Method

Last Updated : 31 Jul, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report

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

Next Article

Similar Reads