Skip to content

Commit 0936245

Browse files
authored
Merge pull request #2341 from vsoni101/patch-1
Update article.md in section 2.8
2 parents 1e4b9e4 + 3d86152 commit 0936245

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

1-js/02-first-steps/08-operators/article.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ alert(2 + 2 + '1' ); // "41" and not "221"
106106
107107
Here, operators work one after another. The first `+` sums two numbers, so it returns `4`, then the next `+` adds the string `1` to it, so it's like `4 + '1' = 41`.
108108

109+
```js run
110+
alert('1' + 2 + 2); // "122" and not "14"
111+
```
112+
Here, the first operand is a string, the compiler treats the other two operands as strings too. The `2` gets concatenated to `'1'`, so it's like `'1' + 2 = "12"` and `"12" + 2 = "122"`.
113+
109114
The binary `+` is the only operator that supports strings in such a way. Other arithmetic operators work only with numbers and always convert their operands to numbers.
110115
111116
Here's the demo for subtraction and division:

0 commit comments

Comments
 (0)