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.

The addition (+) operator produces the sum of numeric operands or string concatenation.

Try it

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"

Syntax

js
x + y

Description

The + operator is overloaded for two distinct operations: numeric addition and string concatenation. When evaluating, it first coerces both operands to primitives. Then, the two operands' types are tested:

String concatenation is often thought to be equivalent with toString() in priority. If the expression has a Temporal, whose objects' valueOf() methods all throw.

js
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 perform string coercion.

Examples

Addition using numbers

js
1 + 2; / 3

Other non-string, non-BigInt values are coerced to numbers:

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

Addition using BigInts

js
1n + 2n; / 3n

You cannot mix BigInt and number operands in addition.

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
"1" + 2n; / TypeError: Cannot mix BigInt and other types, use explicit conversions

To do addition with a BigInt and a non-BigInt, convert either operand:

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

Addition using strings

If one of the operands is a string, the other is converted to a string and they are concatenated:

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

Specifications

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

Browser compatibility

See also