相乘運算子(*)

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.

相乘運算子(*)是用來取得兩個運算元的乘積。

嘗試一下

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

語法

js
x * y

範例

乘以數字

js
2 * 2; // 4
-2 * 2; // -4

乘以無限(Infinity)

js
Infinity * 0; // NaN
Infinity * Infinity; // Infinity

乘以非數字

js
"foo" * 2; // NaN

規範

Specification
ECMAScript® 2025 Language Specification
# sec-multiplicative-operators

瀏覽器相容性

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
Multiplication (*)

Legend

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

Full support
Full support

參見