Lodash _.not() Method
Last Updated :
29 Sep, 2020
The Lodash _.not() method returns a boolean value which is the opposite of the truthiness boolean value of the given value.
Syntax:
_.not( value );
Parameters: This method takes one parameter as mentioned above and described below:
- value: Given value for returning opposite boolean.
Return Value: This method returns a Boolean value.
Note: This will not work in normal JavaScript because it requires the lodash.js contrib library to be installed. Lodash.js contrib library can be installed using npm install lodash-contrib –save.
Example 1:
Javascript
var _ = require( 'lodash-contrib' );
var bool = _.not( true );
console.log( "Opposite boolean value 'true' is : " , bool);
var bool = _.not( false );
console.log( "Opposite boolean value 'false' is : " , bool);
|
Output:
Opposite boolean value 'true' is : false
Opposite boolean value 'false' is : true
Example 2:
Javascript
var _ = require( 'lodash-contrib' );
var bool = _.not( 0 );
console.log( "Opposite boolean value '0' is : " , bool);
var bool = _.not( 1 );
console.log( "Opposite boolean value '1' is : " , bool);
var bool = _.not( 10 );
console.log( "Opposite boolean value '10' is : " , bool);
|
Output:
Opposite boolean value '0' is : true
Opposite boolean value '1' is : false
Opposite boolean value '10' is : false
Example 3:
Javascript
var _ = require( 'lodash-contrib' );
var bool = _.not( {} );
console.log( "Opposite boolean value empty object is : " , bool);
var bool = _.not( { 'G' : "GeeksforGeeks" } );
console.log( "Opposite boolean value object is : " , bool);
var bool = _.not( null );
console.log( "Opposite boolean value 'null' is : " , bool);
|
Output:
Opposite boolean value empty object is : false
Opposite boolean value object is : false
Opposite boolean value 'null' is : true
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...