Skip to content
Related Articles

Related Articles

Improve Article

Underscore.js _.neg() Method

  • Last Updated : 07 Aug, 2020

The _.neg() method returns a new number with opposite sign value of the given number.

Syntax:

_.neg( value );

Parameters: This method takes n values to operate on them.

Return Value: This method returns a new number with opposite sign value of the given number.

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 n  = _.neg( -1 );
  
console.log("Opposite sign value number is :", n);

Output:

Opposite sign value number is : 1

Example 2:




// Defining underscore contrib variable
var _ = require('underscore-contrib'); 
  
var n  = _.neg( 1 );
  
console.log("Opposite sign value number is :", n);

Output:

Opposite sign value number is : -1

Example 3:




// Defining underscore contrib variable
var _ = require('underscore-contrib'); 
  
var n  = _.neg( -3 );
  
console.log("Opposite sign value number is :", n);

Output:

Opposite sign value number is : 3

Example 4:




// Defining underscore contrib variable
var _ = require('underscore-contrib'); 
  
var n  = _.neg( 6 );
  
console.log("Opposite sign value number is :", n);

Output:

Opposite sign value number is : -6



My Personal Notes arrow_drop_up
Recommended Articles
Page :