What is the value of 2 + '2' in JavaScript?

The story behind the answer

In JavaScript, the value of `2 + '2'` is the string `"22"`.

The binary plus operator performs either numeric addition or string concatenation. When one operand is already a string, JavaScript converts the other operand to a string and joins the two values, so the number `2` becomes the text `"2"`, producing `"22"` rather than `4` or the number `4`.

This is one example of JavaScript's implicit type coercion. The result is important: `2 + '2'` produces a string, while `2 + 2` produces the number `4`. Developers can force numeric addition with an explicit conversion such as `Number('2')`, or with the unary plus in simple cases: `2 + +'2'` evaluates to `4`.

Evaluation order also matters. Expressions such as `1 + 2 + '3'` first add the numbers to get `3`, then concatenate to form `"33"`. Parentheses make the intended conversion or grouping clearer and help prevent surprising output.

Source: Wikipedia · fact-checked Aug. 2026

Add question to a list

Choose a list to keep this question in: