Open In App

Underscore.js _.bitwiseNot() Method

The _.bitwiseNot() method returns the result of using the ~ operator on the argument.

Syntax:



_.bitwiseNot( value );

Parameters: This method takes a value to operate ~ operator on it.

Return Value: This method returns the result of using the ~ operator on the argument.



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: 




// Defining underscore contrib variable
var _ = require('underscore-contrib'); 
  
var bN  = _.bitwiseNot( 1 );
  
console.log("The bitwiseNot is :", bN);

Output:

The bitwiseNot is : -2

Example 2:




// Defining underscore contrib variable
var _ = require('underscore-contrib'); 
  
var bN  = _.bitwiseNot( 10 );
  
console.log("The bitwiseNot is :", bN);

Output:

The bitwiseNot is : -11

Example 3: 




// Defining underscore contrib variable
var _ = require('underscore-contrib'); 
  
var bN  = _.bitwiseNot( 100 );
  
console.log("The bitwiseNot is :", bN);

Output:

The bitwiseNot is : -101

Article Tags :