Underscore.js _.falsey() Method

The _.falsey() method checks whether the given value is falsey or not, correspondingly returning a boolean value. A falsey value is one that coerces to false in a boolean context.
Syntax:
_.falsey( value );
Parameters:
- value: Given value is to be checked for falsey value.
Return Value: This method returns a Boolean value (Returns true if the given value is falsey, 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: False boolean always returns true.
Javascript
// Defining underscore contrib variable var _ = require('underscore-contrib'); var bool = _.falsey(false);; console.log("Given Value is Falsey : ",bool); |
Output:
Given Value is Falsey : true
Example 2: Existing values return a true boolean, hence this method returns false.
Javascript
// Defining underscore contrib variable var _ = require('underscore-contrib'); var bool = _.falsey(10);; console.log("Given Value is Falsey : ",bool); |
Output:
Given Value is Falsey : false
Example 3:
Javascript
// Defining underscore contrib variable var _ = require('underscore-contrib'); var bool = _.falsey([ 1, 2, 3 ]);; console.log("Given Value is Falsey : ",bool); |
Output:
Given Value is Falsey : false
Example 4:
Javascript
// Defining underscore contrib variable var _ = require('underscore-contrib'); var bool = _.falsey(true);; console.log("Given Value is Falsey : ",bool); |
Output:
Given Value is Falsey : false
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!



