Addition (+)
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.
Theaddition (+) operator produces the sum of numeric operands or string concatenation.
In this article
Try it
console.log(2 + 2);// Expected output: 4console.log(2 + true);// Expected output: 3console.log("hello " + "everyone");// Expected output: "hello everyone"console.log(2001 + ": A Space Odyssey");// Expected output: "2001: A Space Odyssey"Syntax
x + yDescription
The+ operator is overloaded for two distinct operations: numeric addition and string concatenation. When evaluating, it firstcoerces both operands to primitives. Then, the two operands' types are tested:
- If one side is a string, the other operand is alsoconverted to a string and they are concatenated.
- If they are bothBigInts, BigInt addition is performed. If one side is a BigInt but the other is not, a
TypeErroris thrown. - Otherwise, both sides areconverted to numbers, and numeric addition is performed.
String concatenation is often thought to be equivalent withtemplate literals orString.prototype.concat(), but they are not. Addition coerces the expression to aprimitive, which callsvalueOf() in priority; on the other hand, template literals andconcat() coerce the expression to astring, which callstoString() in priority. If the expression has a[Symbol.toPrimitive]() method, string concatenation calls it with"default" as hint, while template literals use"string". This is important for objects that have different string and primitive representations — such asTemporal, whose objects'valueOf() methods all throw.
const t = Temporal.Now.instant();"" + t; // Throws TypeError`${t}`; // '2022-07-31T04:48:56.113918308Z'"".concat(t); // '2022-07-31T04:48:56.113918308Z'You are advised to not use"" + x to performstring coercion.
Examples
>Addition using numbers
1 + 2; // 3Other non-string, non-BigInt values are coerced to numbers:
true + 1; // 2false + false; // 0Addition using BigInts
1n + 2n; // 3nYou cannot mix BigInt and number operands in addition.
1n + 2; // TypeError: Cannot mix BigInt and other types, use explicit conversions2 + 1n; // TypeError: Cannot mix BigInt and other types, use explicit conversions"1" + 2n; // TypeError: Cannot mix BigInt and other types, use explicit conversionsTo do addition with a BigInt and a non-BigInt, convert either operand:
1n + BigInt(2); // 3nNumber(1n) + 2; // 3Addition using strings
If one of the operands is a string, the other is converted to a string and they are concatenated:
"foo" + "bar"; // "foobar"5 + "foo"; // "5foo""foo" + false; // "foofalse""2" + 2; // "22"Specifications
| Specification |
|---|
| ECMAScript® 2026 Language Specification> # sec-addition-operator-plus> |