| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/Addition | [Back] [Original] |
Get to know MDN better
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"
x + y
String.prototype.concat() valueOf() concat() toString() [Symbol.toPrimitive]() "default" "string" Temporal valueOf()
const t = Temporal.Now.instant();
"" + t; // TypeError
`${t}`; // '2022-07-31T04:48:56.113918308Z'
"".concat(t); // '2022-07-31T04:48:56.113918308Z'
1 + 2; // 3
true + 1; // 2
false + false; // 0
1n + 2n; // 3n
nullundefined
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
"1" + 2n; // "12"
1n + BigInt(2); // 3n
Number(1n) + 2; // 3
"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 |