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
+18-11Lines changed: 18 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ In this chapter we concentrate on aspects that are not covered by school arithme
11
11
Before we move on, let's grasp the common terminology.
12
12
13
13
-*An operand* -- is what operators are applied to. For instance in multiplication `5 * 2` there are two operands: the left operand is `5`, and the right operand is `2`. Sometimes people say "arguments" instead of "operands".
14
-
- An operator is *unary* if it has a single operand. For example, the unary negation `"-"` reverses the sign of the number:
14
+
- An operator is *unary* if it has a single operand. For example, the unary negation `-` reverses the sign of the number:
15
15
16
16
```js run
17
17
let x =1;
@@ -34,7 +34,7 @@ Before we move on, let's grasp the common terminology.
34
34
35
35
Now let's see special features of JavaScript operators that are beyond school arithmetics.
36
36
37
-
Usually the plus operator `'+'` sums numbers.
37
+
Usually the plus operator `+` sums numbers.
38
38
39
39
But if the binary `+` is applied to strings, it merges (concatenates) them:
40
40
@@ -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,7 +54,14 @@ 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
-
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.
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
+
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.
58
65
59
66
For instance, subtraction and division:
60
67
@@ -65,7 +72,7 @@ alert( '6' / '2' ); // 3
65
72
66
73
## Numeric conversion, unary +
67
74
68
-
The plus `+` exist in two forms. The binary form that we used above and the unary form.
75
+
The plus `+` exists in two forms. The binary form that we used above and the unary form.
69
76
70
77
The unary plus or, in other words, the plus operator `+` applied to a single value, doesn't do anything with numbers, but if the operand is not a number, then it is converted into it.
71
78
@@ -86,9 +93,9 @@ alert( +"" ); // 0
86
93
*/!*
87
94
```
88
95
89
-
It actually does the same as `Number(...)`, but shorter.
96
+
It actually does the same as `Number(...)`, but is shorter.
90
97
91
-
A need to convert string to number arises very often. For example, if we are getting values from HTML form fields, then they are usually strings.
98
+
A need to convert strings to numbers arises very often. For example, if we are getting values from HTML form fields, then they are usually strings.
92
99
93
100
What if we want to sum them?
94
101
@@ -246,14 +253,14 @@ So, there are special operators for that:
246
253
247
254
```js run no-beautify
248
255
let counter = 2;
249
-
counter++; // works same as counter = counter + 1, but shorter
256
+
counter++; // works the same as counter = counter + 1, but is shorter
250
257
alert( counter ); // 3
251
258
```
252
259
- **Decrement** `--` decreases a variable by 1:
253
260
254
261
```js run no-beautify
255
262
let counter = 2;
256
-
counter--; // works same as counter = counter - 1, but shorter
263
+
counter--; // works the same as counter = counter - 1, but is shorter
257
264
alert( counter ); // 1
258
265
```
259
266
@@ -401,9 +408,9 @@ alert( n ); // 16 (right part evaluated first, same as n *= 8)
401
408
402
409
## Comma
403
410
404
-
The comma operator `','` is one of most rare and unusual operators. Sometimes it's used to write shorter code, so we need to know it in order to understand what's going on.
411
+
The comma operator `,` is one of most rare and unusual operators. Sometimes it's used to write shorter code, so we need to know it in order to understand what's going on.
405
412
406
-
The comma operator allows us to evaluate several expressions, dividing them with a comma `','`. Each of them is evaluated, but the result of only the last one is returned.
413
+
The comma operator allows us to evaluate several expressions, dividing them with a comma `,`. Each of them is evaluated, but the result of only the last one is returned.
Copy file name to clipboardExpand all lines: 1-js/05-data-types/02-number/9-random-int-min-max/solution.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ Now we can clearly see that `1` gets twice less values than `2`. And the same wi
27
27
28
28
# The correct solution
29
29
30
-
There are many correct solutions to the task. One of them is to adjust interval borders. To ensure the same intervals, we can generate values from `0.5 to 2.5`, thus adding the required probabilities to the edges:
30
+
There are many correct solutions to the task. One of them is to adjust interval borders. To ensure the same intervals, we can generate values from `0.5 to 3.5`, thus adding the required probabilities to the edges:
0 commit comments