相加運算子(+)

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.

相加運算子(+)用來處理數字的相加或是進行字串的串聯。

嘗試一下

語法

js
x + y

範例

數字相加

js
// Number + Number -> addition
1 + 2; // 3
// Boolean + Number -> addition
true + 1; // 2
// Boolean + Boolean -> addition
false + false; // 0

字串串聯

js
// String + String -> concatenation
"foo" + "bar"; // "foobar"
// Number + String -> concatenation
5 + "foo"; // "5foo"
// String + Boolean -> concatenation
"foo" + false; // "foofalse"

規範

Specification
ECMAScript Language Specification
# sec-addition-operator-plus

瀏覽器相容性

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
Addition (+)

Legend

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

Full support
Full support

參見