operators

This commit is contained in:
Ilya Kantor 2015-08-18 15:15:50 +03:00
parent 68e49397c1
commit fa4c9bed29

View file

@ -58,6 +58,18 @@ alert( '1' + 2 ); // "12"
alert( 2 + '1' ); // "21" alert( 2 + '1' ); // "21"
``` ```
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.
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.
For instance:
```js
//+ run
alert( 2 - '1' ); // 1
alert( 6 / '2' ); // 3
```
### Преобразование к числу, унарный плюс + ### Преобразование к числу, унарный плюс +