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

(+) - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

(+)

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 7.

(+) , .

In this article

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

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

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

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

js
x + y

+ . . , .

String.prototype.concat() , . valueOf() . , concat() toString() . @@toPrimitive , "default" , "string" . . valueOf() Temporal .

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

"" + x .

Number

js
// Number + Number -> 
1 + 2; // 3

// Boolean + Number -> 
true + 1; // 2

// Boolean + Boolean -> 
false + false; // 0

BigInt

js
// BigInt + BigInt -> 
1n + 2n; // 3n

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

// BigInt  non-BigInt  ,    .
1n + BigInt(2); // 3n
Number(1n) + 2; // 3

js
// String + String -> 
"foo" + "bar"; // "foobar"

// Number + String -> 
5 + "foo"; // "5foo"

// String + Boolean -> 
"foo" + false; // "foofalse"

Specification
ECMAScript 2027 LanguageSpecification
# sec-addition-operator-plus


Web Proxy Viewer  |  New URL  |  Original Page