Skip to content

Commit fa4c9be

Browse files
committed
operators
1 parent 68e4939 commit fa4c9be

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

1-js/2-first-steps/8-operators/article.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ alert( '1' + 2 ); // "12"
5858
alert( 2 + '1' ); // "21"
5959
```
6060

61+
Note that it doesn't matter whether the first operand is a string or the second one. The rule is simple: if any of operands is a string, then convert the other one into a string as well.
62+
63+
The string concatenation and conversion is the special feature of the binary plus `"+"`. Other arithmetic operators work only with numbers. They always convert their operands into numbers.
64+
65+
For instance:
66+
67+
```js
68+
//+ run
69+
alert( 2 - '1' ); // 1
70+
alert( 6 / '2' ); // 3
71+
```
72+
6173

6274

6375
### Преобразование к числу, унарный плюс +

0 commit comments

Comments
 (0)