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/08-operators/3-primitive-conversions-questions/solution.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,4 +22,4 @@ undefined + 1 = NaN // (6)
22
22
4. The subtraction always converts to numbers, so it makes `" -9 "` a number `-9` (ignoring spaces around it).
23
23
5.`null` becomes `0` after the numeric conversion.
24
24
6.`undefined` becomes `NaN` after the numeric conversion.
25
-
7. Space characters, are trimmed off string start and end when a string is converted to a number. Here the whole string consists of space characters, such as `\t`, `\n` and a "regular" space between them. So, similarly to an empty string, it becomes `0`.
25
+
7. Space characters are trimmed off string start and end when a string is converted to a number. Here the whole string consists of space characters, such as `\t`, `\n` and a "regular" space between them. So, similarly to an empty string, it becomes `0`.
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/08-operators/article.md
+16-15Lines changed: 16 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,8 +50,9 @@ The result of `a % b` is the [remainder](https://en.wikipedia.org/wiki/Remainder
50
50
For instance:
51
51
52
52
```js run
53
-
alert( 5 % 2 ); // 1, a remainder of 5 divided by 2
54
-
alert( 8 % 3 ); // 2, a remainder of 8 divided by 3
53
+
alert( 5 % 2 ); // 1, the remainder of 5 divided by 2
54
+
alert( 8 % 3 ); // 2, the remainder of 8 divided by 3
55
+
alert( 8 % 4 ); // 0, the remainder of 8 divided by 4
55
56
```
56
57
57
58
### Exponentiation **
@@ -68,7 +69,7 @@ alert( 2 ** 3 ); // 2³ = 8
68
69
alert( 2 ** 4 ); // 2⁴ = 16
69
70
```
70
71
71
-
Just like in maths, the exponentiation operator is defined for non-integer numbers as well.
72
+
Just like in maths, the exponentiation operator is defined for non-integer numbers as well.
72
73
73
74
For example, a square root is an exponentiation by ½:
74
75
@@ -80,7 +81,7 @@ alert( 8 ** (1/3) ); // 2 (power of 1/3 is the same as a cubic root)
80
81
81
82
## String concatenation with binary +
82
83
83
-
Let's meet features of JavaScript operators that are beyond school arithmetics.
84
+
Let's meet the features of JavaScript operators that are beyond school arithmetics.
84
85
85
86
Usually, the plus operator `+` sums numbers.
86
87
@@ -194,18 +195,18 @@ Here's an extract from the [precedence table](https://developer.mozilla.org/en-U
194
195
| Precedence | Name | Sign |
195
196
|------------|------|------|
196
197
|...|...|...|
197
-
|15| unary plus |`+`|
198
-
|15| unary negation |`-`|
199
-
|14| exponentiation |`**`|
200
-
|13| multiplication |`*`|
201
-
|13| division |`/`|
202
-
|12| addition |`+`|
203
-
|12| subtraction |`-`|
198
+
|14| unary plus |`+`|
199
+
|14| unary negation |`-`|
200
+
|13| exponentiation |`**`|
201
+
|12| multiplication |`*`|
202
+
|12| division |`/`|
203
+
|11| addition |`+`|
204
+
|11| subtraction |`-`|
204
205
|...|...|...|
205
206
|2| assignment |`=`|
206
207
|...|...|...|
207
208
208
-
As we can see, the "unary plus" has a priority of`15` which is higher than the `12`of"addition" (binary plus). That's why, in the expression `"+apples + +oranges"`, unary pluses work before the addition.
209
+
As we can see, the "unary plus" has a priority of`14` which is higher than the `11`of"addition" (binary plus). That's why, in the expression `"+apples + +oranges"`, unary pluses work before the addition.
209
210
210
211
## Assignment
211
212
@@ -303,9 +304,9 @@ Such operators have the same precedence as a normal assignment, so they run afte
303
304
```js run
304
305
let n = 2;
305
306
306
-
n *= 3 + 5;
307
+
n *= 3 + 5; // right part evaluated first, same as n *= 8
307
308
308
-
alert( n ); // 16 (right part evaluated first, same as n *= 8)
309
+
alert( n ); // 16
309
310
```
310
311
311
312
## Increment/decrement
@@ -437,7 +438,7 @@ The list of operators:
437
438
- RIGHT SHIFT ( `>>` )
438
439
- ZERO-FILL RIGHT SHIFT ( `>>>` )
439
440
440
-
These operators are used very rarely, when we need to fiddle with numbers on the very lowest (bitwise) level. We won't need these operators any time soon, as web development has little use of them, but in some special areas, such as cryptography, they are useful. You can read the [Bitwise Operators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Bitwise) chapter on MDN when a need arises.
441
+
These operators are used very rarely, when we need to fiddle with numbers on the very lowest (bitwise) level. We won't need these operators any time soon, as web development has little use of them, but in some special areas, such as cryptography, they are useful. You can read the [Bitwise Operators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#bitwise_operators) chapter on MDN when a need arises.
0 commit comments