JavaScript -x Unary negation Operator
The unary negation operator (-) placed before a value converts it to a number and flips its sign.
Description
The unary negation operator - converts its operand to a number and returns its negative. It also works with BigInts.
Like unary plus, the value is converted to a number before it's negated, so -'5' is -5 and -'abc' is NaN. Negating zero gives -0, which is equal to 0 with === but can be told apart with Object.is() and shows up in results such as 1 / -0 being -Infinity.
Because unary operators can't appear directly before the base of an exponentiation, -2 ** 2 is a syntax error; write -(2 ** 2) or (-2) ** 2. To get the absolute value, the opposite of negation, use Math.abs().
Properties
- Operator
-x- Category
- Unary
- Precedence
- 14 (1 is lowest, 18 is highest)
- Associativity
- right-to-left
Syntax
-xExample
Browser Support
The following information will show you the current browser support for the -x operator. Hover over a browser icon to see the version that first introduced support for this operator.
Desktop





Tablets & Mobile





