Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc.
The _.bitwiseNot() method is used to return the result of using the Bitwise NOT operator (~) on the given argument.
Syntax:
_.bitwiseNot( value );
Parameters: This method takes a single value as parameter as mentioned above and described below:
- value: It is the value on which to apply the Bitwise NOT operator (~).
Return Value: This method returns the result of using the Bitwise NOT operator (~) on the argument.
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
// Adding lodash-contrib library var _ = require( 'lodash-contrib' ); // Using the _.bitwiseNot() method var bN = _.bitwiseNot( 1 ); console.log( "The bitwiseNot is :" , bN); |
Output:
The bitwiseNot is : -2
Example 2:
Javascript
// Adding lodash-contrib library var _ = require( 'lodash-contrib' ); // Using the _.bitwiseNot() method var bN = _.bitwiseNot( 10 ); console.log( "The bitwiseNot is :" , bN); |
Output:
The bitwiseNot is : -11
Example 3:
Javascript
// Adding lodash-contrib library var _ = require( 'lodash-contrib' ); // Using the _.bitwiseNot() method var bN = _.bitwiseNot( 100 ); console.log( "The bitwiseNot is :" , bN); |
Output:
The bitwiseNot is : -101