Unäre Negation (-)

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Der unäre Negationsoperator (-) steht vor seinem Operanden und negiert diesen.

Probieren Sie es aus

Syntax

js
-x

Beschreibung

Der - Operator ist für zwei Arten von Operanden überladen: Zahl und BigInt. Zunächst wandelt er den Operanden in einen numerischen Wert um und testet dessen Typ. Er führt eine BigInt-Negation durch, wenn der Operand zu einem BigInt wird; andernfalls führt er eine Zahlennegation durch.

Beispiele

Zahlen negieren

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

Nicht-Zahlen negieren

Der unäre Negationsoperator kann eine Nicht-Zahl in eine Zahl umwandeln.

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

// y is -4

BigInts können mit dem unären Negationsoperator negiert werden.

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

// y is -4n

Spezifikationen

Specification
ECMAScript® 2025 Language Specification
# sec-unary-minus-operator

Browser-Kompatibilität

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
Unary negation (-)

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

Siehe auch