--- title: Unary negation (-) slug: Web/JavaScript/Reference/Operators/Unary_negation translation_of: Web/JavaScript/Reference/Operators/Unary_negation ---
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
Specification |
---|
{{SpecName('ESDraft', '#sec-unary-minus-operator', 'Unary negation operator')}} |
{{Compat("javascript.operators.unary_negation")}}