The unary minus operator

The unary minus operator (-...) will first convert its operand into Number in the same way as the unary + operator, detailed in the last section, and will then negate it:

-55;    // => -55
-(-55); // => 55
-'55'; // => -55

Its usage is fairly straightforward and intuitive, although, as with unary +, it's useful to disambiguate cases where you have a unary operator next to its binary operator counterpart. Cases like these can be confusing: 

number - -otherNumber

It is best, in these situations, to lend clarity with parentheses:

number - (-otherNumber)

The unary minus operator is usually only used directly with a literal number operand to specify a negative value. As with all other arithmetic operators, we should ensure that our intent is clear and that we are not confusing people with long or confusing expressions.

Now that we've explored arithmetic operators, we can begin to look into logical operators. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.130.24