Multiplikation (*)
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.
Please take two minutes to fill out our short survey.
Der Multiplikations-Operator (*
) liefert das Produkt der Operanden.
Probieren Sie es aus
console.log(3 * 4);
// Expected output: 12
console.log(-3 * 4);
// Expected output: -12
console.log("3" * 2);
// Expected output: 6
console.log("foo" * 2);
// Expected output: NaN
Syntax
x * y
Beschreibung
Der *
Operator ist für zwei Arten von Operanden überladen: Zahl und BigInt. Er zwingt zunächst beide Operanden zur numerischen Werteumwandlung und prüft deren Typen. Er führt eine BigInt-Multiplikation durch, wenn beide Operanden zu BigInts werden; andernfalls führt er eine Zahlenmultiplikation durch. Ein TypeError
wird ausgelöst, wenn ein Operand ein BigInt wird, der andere jedoch eine Zahl bleibt.
Beispiele
Multiplikation mit Zahlen
2 * 2; // 4
-2 * 2; // -4
Infinity * 0; // NaN
Infinity * Infinity; // Infinity
Andere Nicht-BigInt-Werte werden in Zahlen umgewandelt:
"foo" * 2; // NaN
"2" * 2; // 4
Multiplikation mit BigInts
2n * 2n; // 4n
-2n * 2n; // -4n
Sie können BigInt- und Zahlen-Operanden in der Multiplikation nicht mischen.
2n * 2; // TypeError: Cannot mix BigInt and other types, use explicit conversions
2 * 2n; // TypeError: Cannot mix BigInt and other types, use explicit conversions
Um eine Multiplikation mit einem BigInt und einem Nicht-BigInt durchzuführen, konvertieren Sie einen der Operanden:
2n * BigInt(2); // 4n
Number(2n) * 2; // 4
Spezifikationen
Specification |
---|
ECMAScript® 2026 Language Specification # sec-multiplicative-operators |