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/2-first-steps/8-operators/article.md
+19-32Lines changed: 19 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,19 +1,17 @@
1
1
# Operators
2
2
3
-
Many operators are known to us from the school program. It is an addition `+`, a multiplication `*`, a subsctraction and so on.
3
+
Many operators are known to us from the school program. It is an addition `+`, a multiplication `*`, a substraction `-` and so on.
4
4
5
-
In this chapter we mainly concentrate on aspects not covered by the arithmetic.
5
+
In this chapter we concentrate on aspects that are not covered by the school arithmetic.
6
6
[cut]
7
7
8
8
## Terms: "unary", "binary", "operand"
9
9
10
-
У операторов есть своя терминология, которая используется во всех языках программирования.
11
-
12
-
Прежде, чем мы двинемся дальше -- несколько терминов, чтобы понимать, о чём речь.
10
+
Before we move on, let's make a dip in the terminology, to understand what we're talking about.
13
11
14
12
<ul>
15
-
<li>*Операнд* -- то, к чему применяется оператор. Например: `5 * 2` -- оператор умножения с левым и правым операндами. Другое название: "аргумент оператора".</li>
16
-
<li>*Унарным* называется оператор, который применяется к одному выражению. Например, оператор унарный минус `"-"` меняет знак числа на противоположный:
13
+
<li>*An operand* -- is what operators are applied to. For instance in `5 * 2` the left operand of the multiplication is `5`, the right operand is `2`. Another word is "an argument of an operator".</li>
14
+
<li>*Unary* is the operator which has a single operand. For example, the unary minus `"-"` reverses the sign of the number:
17
15
18
16
```js
19
17
//+ run
@@ -22,56 +20,44 @@ var x = 1;
22
20
*!*
23
21
x =-x;
24
22
*/!*
25
-
alert( x ); // -1, применили унарный минус
23
+
alert( x ); // -1, unary minus was applied
26
24
```
27
25
28
26
</li>
29
-
<li>*Бинарным* называется оператор, который применяется к двум операндам. Тот же минус существует и в бинарной форме:
27
+
<li>*Binary* is the operator which has two operands. The same minus exists in the binary form as well:
30
28
31
29
```js
32
30
//+ run no-beautify
33
31
var x =1, y =3;
34
-
alert( y - x ); // 2, бинарный минус
32
+
alert( y - x ); // 2, binary minus
35
33
```
34
+
35
+
Formally, we're talking about the two different operators here: the unary minus (single operand, reverses the sign) and the binary minus (two operands, substracts).
36
36
</li>
37
37
</ul>
38
38
39
39
40
-
## Сложение строк, бинарный +
40
+
## Strings concatenation, binary +
41
41
42
-
Обычно при помощи плюса`'+'`складывают числа.
42
+
Usually the plus operator`'+'`sums numbers.
43
43
44
-
Но если бинарный оператор `'+'` применить к строкам, то он их объединяет в одну:
44
+
But if the binary `+` is applied to strings, it merges (concatenates) them:
45
45
46
46
```js
47
-
vara="моя"+"строка";
48
-
alert( a ); //моястрока
47
+
vars="my"+"string";
48
+
alert( s ); //mystring
49
49
```
50
50
51
-
Иначе говорят, что "плюс производит конкатенацию (сложение) строк".
52
-
53
-
**Если хотя бы один аргумент является строкой, то второй будет также преобразован к строке!**
51
+
If one of operands is a string, then the other one is converted to string too.
54
52
55
-
Причем не важно, справа или слева находится операнд-строка, в любом случае нестроковый аргумент будет преобразован. Например:
53
+
For example:
56
54
57
55
```js
58
56
//+ run
59
57
alert( '1'+2 ); // "12"
60
58
alert( 2+'1' ); // "21"
61
59
```
62
60
63
-
**Это приведение к строке -- особенность исключительно бинарного оператора `"+"`.**
64
-
65
-
Остальные арифметические операторы работают только с числами и всегда приводят аргументы к числу.
0 commit comments