Skip to content

Commit 68e4939

Browse files
committed
operators
1 parent 9585c3e commit 68e4939

1 file changed

Lines changed: 19 additions & 32 deletions

File tree

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

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
# Operators
22

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.
44

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.
66
[cut]
77

88
## Terms: "unary", "binary", "operand"
99

10-
У операторов есть своя терминология, которая используется во всех языках программирования.
11-
12-
Прежде, чем мы двинемся дальше -- несколько терминов, чтобы понимать, о чём речь.
10+
Before we move on, let's make a dip in the terminology, to understand what we're talking about.
1311

1412
<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:
1715

1816
```js
1917
//+ run
@@ -22,56 +20,44 @@ var x = 1;
2220
*!*
2321
x = -x;
2422
*/!*
25-
alert( x ); // -1, применили унарный минус
23+
alert( x ); // -1, unary minus was applied
2624
```
2725

2826
</li>
29-
<li>*Бинарным* называется оператор, который применяется к двум операндам. Тот же минус существует и в бинарной форме:
27+
<li>*Binary* is the operator which has two operands. The same minus exists in the binary form as well:
3028

3129
```js
3230
//+ run no-beautify
3331
var x = 1, y = 3;
34-
alert( y - x ); // 2, бинарный минус
32+
alert( y - x ); // 2, binary minus
3533
```
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).
3636
</li>
3737
</ul>
3838

3939

40-
## Сложение строк, бинарный +
40+
## Strings concatenation, binary +
4141

42-
Обычно при помощи плюса `'+'` складывают числа.
42+
Usually the plus operator `'+'` sums numbers.
4343

44-
Но если бинарный оператор `'+'` применить к строкам, то он их объединяет в одну:
44+
But if the binary `+` is applied to strings, it merges (concatenates) them:
4545

4646
```js
47-
var a = "моя" + "строка";
48-
alert( a ); // моястрока
47+
var s = "my" + "string";
48+
alert( s ); // mystring
4949
```
5050

51-
Иначе говорят, что "плюс производит конкатенацию (сложение) строк".
52-
53-
**Если хотя бы один аргумент является строкой, то второй будет также преобразован к строке!**
51+
If one of operands is a string, then the other one is converted to string too.
5452

55-
Причем не важно, справа или слева находится операнд-строка, в любом случае нестроковый аргумент будет преобразован. Например:
53+
For example:
5654

5755
```js
5856
//+ run
5957
alert( '1' + 2 ); // "12"
6058
alert( 2 + '1' ); // "21"
6159
```
6260

63-
**Это приведение к строке -- особенность исключительно бинарного оператора `"+"`.**
64-
65-
Остальные арифметические операторы работают только с числами и всегда приводят аргументы к числу.
66-
67-
Например:
68-
69-
```js
70-
//+ run
71-
alert( 2 - '1' ); // 1
72-
alert( 6 / '2' ); // 3
73-
```
74-
7561

7662

7763
### Преобразование к числу, унарный плюс +
@@ -80,7 +66,8 @@ alert( 6 / '2' ); // 3
8066

8167
```js
8268
//+ run
83-
alert( +1 ); // 1
69+
alert( +1 );
70+
// 1
8471
alert( +(1 - 2) ); // -1
8572
```
8673

0 commit comments

Comments
 (0)