The unary negation operator (
-
) precedes its operand and negates it.
Operator: -x
const x = 3; const y = -x; // y = -3 // x = 3
The unary negation operator can convert a non-number into a number.
const x = "4"; const y = -x; // y = -4
| 规范 |
|---|
|
ECMAScript (ECMA-262)
The definition of 'Unary negation operator' in that specification. |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Unary negation (
-
)
|
Chrome 1 | Edge 12 | Firefox 1 | IE 3 | Opera 3 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
完整支持