Documentación offline JavaScript main

Unary negation (-)

main Documentación oficial Licencia CC-BY-SA-2.5Descargado el 2026-08-02

En esta página

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

{{InteractiveExample("JavaScript Demo: Unary negation (-) operator")}}

```js interactive-example const x = 4; const y = -x;

console.log(y); // Expected output: -4

const a = "4"; const b = -a;

console.log(b); // Expected output: -4

## Syntax

```js-nolint
-x

Description#

The - operator is overloaded for two types of operands: number and BigInt. It first coerces the operand to a numeric value and tests the type of it. It performs BigInt negation if the operand becomes a BigInt; otherwise, it performs number negation.

Examples#

Negating numbers#

const x = 3;
const y = -x;
// y is -3; x is 3

Negating non-numbers#

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

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

// y is -4

BigInts can be negated using the unary negation operator.

const x = 4n;
const y = -x;

// y is -4n

Specifications#

{{Specifications}}

Browser compatibility#

{{Compat}}

See also#