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/05-types/article.md
+5-3Lines changed: 5 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,13 +46,15 @@ Besides regular numbers, there are so-called "special numeric values" which also
46
46
alert( "not a number" / 2 ); // NaN, such division is erroneous
47
47
```
48
48
49
-
`NaN` is sticky. Any further operation on `NaN` returns `NaN`:
49
+
`NaN` is sticky. Any further mathematical operation on `NaN` returns `NaN`:
50
50
51
51
```js run
52
-
alert( "not a number" / 2 + 5 ); // NaN
52
+
alert( NaN + 1 ); // NaN
53
+
alert( 3 * NaN ); // NaN
54
+
alert( "not a number" / 2 - 1 ); // NaN
53
55
```
54
56
55
-
So, if there's a `NaN` somewhere in a mathematical expression, it propagates to the whole result.
57
+
So, if there's a `NaN` somewhere in a mathematical expression, it propagates to the whole result (there's only one exception to that:`NaN ** 0` is `1`).
56
58
57
59
```smart header="Mathematical operations are safe"
58
60
Doing maths is "safe" in JavaScript. We can do anything: divide by zero, treat non-numeric strings as numbers, etc.
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/12-nullish-coalescing-operator/article.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
@@ -106,7 +106,7 @@ In practice, the zero height is often a valid value, that shouldn't be replaced
106
106
107
107
## Precedence
108
108
109
-
The precedence of the `??` operator is about the same as `||`, just a bit lower. It equals `5` in the [MDN table](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence#Table), while `||` is `6`.
109
+
The precedence of the `??` operator is the same as `||`. They both equal `4` in the [MDN table](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence#Table).
110
110
111
111
That means that, just like `||`, the nullish coalescing operator `??` is evaluated before `=` and `?`, but after most other operations, such as `+`, `*`.
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/17-arrow-functions-basics/article.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,7 +33,7 @@ let sum = function(a, b) {
33
33
alert( sum(1, 2) ); // 3
34
34
```
35
35
36
-
As you can, see `(a, b) => a + b` means a function that accepts two arguments named `a` and `b`. Upon the execution, it evaluates the expression `a + b` and returns the result.
36
+
As you can see,`(a, b) => a + b` means a function that accepts two arguments named `a` and `b`. Upon the execution, it evaluates the expression `a + b` and returns the result.
37
37
38
38
- If we have only one argument, then parentheses around parameters can be omitted, making that even shorter.
39
39
@@ -86,7 +86,7 @@ Like this:
86
86
let sum = (a, b) => { // the curly brace opens a multiline function
87
87
let result = a + b;
88
88
*!*
89
-
return result; // if we use curly braces, then we need an explicit "return"
89
+
return result; // if we use curly braces, then we need an explicit "return"
Copy file name to clipboardExpand all lines: 1-js/04-object-basics/07-optional-chaining/article.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
@@ -25,7 +25,7 @@ That's the expected result. JavaScript works like this. As `user.address` is `un
25
25
26
26
In many practical cases we'd prefer to get `undefined` instead of an error here (meaning "no street").
27
27
28
-
...And another example. In the web development, we can get an object that corresponds to a web page element using a special method call, such as `document.querySelector('.elem')`, and it returns `null` when there's no such element.
28
+
...and another example. In Web development, we can get an object that corresponds to a web page element using a special method call, such as `document.querySelector('.elem')`, and it returns `null` when there's no such element.
29
29
30
30
```js run
31
31
// document.querySelector('.elem') is null if there's no element
Copy file name to clipboardExpand all lines: 1-js/05-data-types/10-destructuring-assignment/article.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
@@ -5,7 +5,7 @@ The two most used data structures in JavaScript are `Object` and `Array`.
5
5
- Objects allow us to create a single entity that stores data items by key.
6
6
- Arrays allow us to gather data items into an ordered list.
7
7
8
-
Although, when we pass those to a function, it may need not an object/array as a whole. It may need individual pieces.
8
+
Although, when we pass those to a function, it may need not be an object/array as a whole. It may need individual pieces.
9
9
10
10
*Destructuring assignment* is a special syntax that allows us to "unpack" arrays or objects into a bunch of variables, as sometimes that's more convenient.
3. We load `3.js`, then if there's no error -- do something else `(*)`.
235
235
236
236
As calls become more nested, the code becomes deeper and increasingly more difficult to manage, especially if we have real code instead of `...` that may include more loops, conditional statements and so on.
@@ -299,7 +299,7 @@ function step3(error, script) {
299
299
}
300
300
```
301
301
302
-
See? It does the same, and there's no deep nesting now because we made every action a separate top-level function.
302
+
See? It does the same thing, and there's no deep nesting now because we made every action a separate top-level function.
303
303
304
304
It works, but the code looks like a torn apart spreadsheet. It's difficult to read, and you probably noticed that one needs to eye-jump between pieces while reading it. That's inconvenient, especially if the reader is not familiar with the code and doesn't know where to eye-jump.
Copy file name to clipboardExpand all lines: 1-js/11-async/03-promise-chaining/article.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
@@ -120,7 +120,7 @@ new Promise(function(resolve, reject) {
120
120
});
121
121
```
122
122
123
-
Here the first `.then` shows `1` and returns `new Promise(…)` in the line `(*)`. After one second it resolves, and the result (the argument of `resolve`, here it's `result * 2`) is passed on to handler of the second `.then`. That handler is in the line `(**)`, it shows `2` and does the same thing.
123
+
Here the first `.then` shows `1` and returns `new Promise(…)` in the line `(*)`. After one second it resolves, and the result (the argument of `resolve`, here it's `result * 2`) is passed on to the handler of the second `.then`. That handler is in the line `(**)`, it shows `2` and does the same thing.
124
124
125
125
So the output is the same as in the previous example: 1 -> 2 -> 4, but now with 1 second delay between `alert` calls.
0 commit comments