Lodash _.neg() Method
Last Updated :
29 Sep, 2020
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc.
The _.neg() method is used to return a new number with the opposite sign value of the given number.
Syntax:
_.neg( value )
Parameters: This method accepts a single parameter as mentioned above and described below:
- value: It is the number to be negated with this method.
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 lodash contrib library to be installed. The Lodash contrib library can be installed using npm install lodash-contrib –save.
Example 1:
Javascript
var _ = require( 'lodash-contrib' );
var n = _.neg( -1 );
console.log(
"Opposite sign value number is :" , n
);
|
Output:
Opposite sign value number is : 1
Example 2:
Javascript
var _ = require( 'lodash-contrib' );
var n = _.neg( 1 );
console.log(
"Opposite sign value number is :" , n
);
|
Output:
Opposite sign value number is : -1
Example 3:
Javascript
var _ = require( 'lodash-contrib' );
var n = _.neg( 60 );
console.log(
"Opposite sign value number is :" , n
);
|
Output:
Opposite sign value number is : -60
Example 4:
Javascript
var _ = require( 'lodash-contrib' );
var n = _.neg( -50 );
console.log(
"Opposite sign value number is :" , n
);
|
Output:
Opposite sign value number is : 50
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...