--- title: Unary negation (-) slug: Web/JavaScript/Reference/Operators/Unary_negation translation_of: Web/JavaScript/Reference/Operators/Unary_negation ---
{{jsSidebar("Operators")}}

The unary negation operator (-) precedes its operand and negates it.

{{EmbedInteractiveExample("pages/js/expressions-unary-negation.html")}}

语法

Operator: -x

Examples

Negating numbers

const x = 3;
const y = -x;

// y = -3
// x = 3

Negating non-numbers

The unary negation operator can convert a non-number into a number.

const x = "4";
const y = -x;

// y = -4

Specifications

Specification
{{SpecName('ESDraft', '#sec-unary-minus-operator', 'Unary negation operator')}}

Browser compatibility

{{Compat("javascript.operators.unary_negation")}}

See also