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
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
var _ = require( 'underscore-contrib' );
var bool = _.falsey(10);;
console.log( "Given Value is Falsey : " ,bool);
|
Output:
Given Value is Falsey : false
Example 3:
Javascript
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
var _ = require( 'underscore-contrib' );
var bool = _.falsey( true );;
console.log( "Given Value is Falsey : " ,bool);
|
Output:
Given Value is Falsey : false
Last Updated :
13 Aug, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...