Underscore.js _.neg() Method
The _.neg() method returns a new number with the 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 the 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: In this example, we will see the use of the _.neg() method
javascript
// Defining underscore contrib variable const _ = require( 'underscore-contrib' ); let n = _.neg(-1); console.log( "Opposite sign value number is :" , n); |
Output:
Opposite sign value number is : 1
Example 2: In this example, we will see the use of the _.neg() method
javascript
// Defining underscore contrib variable const _ = require( 'underscore-contrib' ); let n = _.neg(1); console.log( "Opposite sign value number is :" , n); |
Output:
Opposite sign value number is : -1
Example 3: In this example, we will see the use of the _.neg() method
javascript
// Defining underscore contrib variable const _ = require( 'underscore-contrib' ); let n = _.neg(-3); console.log( "Opposite sign value number is :" , n); |
Output:
Opposite sign value number is : 3
Example 4: In this example, we will see the use of the _.neg() method
javascript
// Defining underscore contrib variable const _ = require( 'underscore-contrib' ); let n = _.neg(6); console.log( "Opposite sign value number is :" , n); |
Output:
Opposite sign value number is : -6