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.
Der Multiplikations-Operator (*
) erzeugt 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: number
und BigInt. Zunächst werden beide Operanden zu numerischen Werten umgewandelt und ihre Typen getestet. Er führt eine Multiplikation von BigInt aus, wenn beide Operanden BigInts werden; andernfalls wird eine Multiplikation von Zahlen durchgeführt. Ein TypeError
wird ausgelöst, wenn ein Operand zu einem BigInt wird, der andere jedoch zu einer Zahl.
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
Es ist nicht möglich, BigInt- und Zahl-Operanden bei der Multiplikation zu 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 auszuführen, konvertieren Sie einen der Operanden:
2n * BigInt(2); // 4n
Number(2n) * 2; // 4
Spezifikationen
Specification |
---|
ECMAScript® 2025 Language Specification # sec-multiplicative-operators |
Browser-Kompatibilität
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Multiplication ( * ) |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support