Change minus to plus, minus to minus with JavaScript

2019-06-15Javascript

JavaScript is a way to change negative values ​​to positive values ​​and positive values ​​to negative values.

Minus Plus, plus minus

Make minus in the formula and minus in the formula

-(Value)

Sample code

Let N1 =-(12);
Let N2 =-(-10);

Console.log (N1, N2);
-12, 10

In the code above, 12 is inverted to a negative value of -12 and -10 is inverted to a positive value of 10.

Make only minus

Use Math.abs ()

It is a method to change only negative value to positive value by Math.abs ().

Math.Abs (value)

Math.Abs () Sample code

Let N1 = Math.abs (12);
Let N2 = Math.abs (-10);

Console.log (N1, N2);
12, 10

In the above code, 12 remains unchanged and -10 is inverted to 10.

2019-06-15Javascript

Posted by Yousuke.U