You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/07-operators/article.md
+8-1Lines changed: 8 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -43,7 +43,7 @@ let s = "my" + "string";
43
43
alert(s); // mystring
44
44
```
45
45
46
-
Note that if any of operands is a string, then the other one is converted to a string too.
46
+
Note that if any ofthe operands is a string, then the other one is converted to a string too.
47
47
48
48
For example:
49
49
@@ -54,6 +54,13 @@ alert( 2 + '1' ); // "21"
54
54
55
55
See, it doesn't matter whether the first operand is a string or the second one. The rule is simple: if either operand is a string, then convert the other one into a string as well.
56
56
57
+
However, note that operations run from left to right. If there are two numbers followed by a string, the numbers will be added before being converted to a string:
58
+
59
+
60
+
```js run
61
+
alert(2 + 2 + '1' ); // "41" and not "221"
62
+
```
63
+
57
64
String concatenation and conversion is a special feature of the binary plus `+`. Other arithmetic operators work only with numbers. They always convert their operands to numbers.
0 commit comments