[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/Addition [Back]  [Original]

(+) - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

(+)

Baseline

20157

(+)

console.log(2 + 2);
// : 4

console.log(2 + true);
// : 3

console.log("hello " + "everyone");
// : "hello everyone"

console.log(2001 + ": A Space Odyssey");
// : "2001: A Space Odyssey"

js
x + y

+ 2 2

String.prototype.concat() valueOf() concat() toString() [Symbol.toPrimitive]() "default" "string" Temporal valueOf()

js
const t = Temporal.Now.instant();
"" + t; // TypeError 
`${t}`; // '2022-07-31T04:48:56.113918308Z'
"".concat(t); // '2022-07-31T04:48:56.113918308Z'

"" + x

js
1 + 2; // 3

js
true + 1; // 2
false + false; // 0

js
1n + 2n; // 3n

nullundefined

js
1n + 2; // TypeError: Cannot mix BigInt and other types, use explicit conversions
2 + 1n; // TypeError: Cannot mix BigInt and other types, use explicit conversions

TypeError

js
"1" + 2n; // "12"

js
1n + BigInt(2); // 3n
Number(1n) + 2; // 3

js
"foo" + "bar"; // "foobar"
5 + "foo"; // "5foo"
"foo" + false; // "foofalse"
"2" + 2; // "22"

ECMAScript 2027 LanguageSpecification
# sec-addition-operator-plus


Web Proxy Viewer  |  New URL  |  Original Page