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/06-advanced-functions/08-settimeout-setinterval/article.md
+2-3
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,6 @@ There are two methods for it:
9
9
10
10
These methods are not a part of JavaScript specification. But most environments have the internal scheduler and provide these methods. In particular, they are supported in all browsers and Node.js.
11
11
12
-
13
12
## setTimeout
14
13
15
14
The syntax:
@@ -291,9 +290,9 @@ For server-side JavaScript, that limitation does not exist, and there exist othe
291
290
- To cancel the execution, we should call `clearInterval/clearTimeout` with the value returned by `setInterval/setTimeout`.
292
291
- Nested `setTimeout` calls is a more flexible alternative to `setInterval`. Also they can guarantee the minimal time *between* the executions.
293
292
- Zero delay scheduling with `setTimeout(func, 0)` (the same as `setTimeout(func)`) is used to schedule the call "as soon as possible, but after the current code is complete".
294
-
- The browsere ensures that for five or more nested call of `setTimeout`, or for zero-delay `setInterval`, the real delay between calls is at least 4ms. That's for historical reasons.
293
+
- The browser limits the minimal delay for five or more nested call of `setTimeout` or for `setInterval` (after 5th call) to 4ms. That's for historical reasons.
295
294
296
-
Please note that all scheduling methods do not *guarantee* the exact delay. We should not rely on that in the scheduled code.
295
+
Please note that all scheduling methods do not *guarantee* the exact delay.
297
296
298
297
For example, the in-browser timer may slow down for a lot of reasons:
Copy file name to clipboardExpand all lines: 1-js/07-object-properties/01-property-descriptors/article.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -122,7 +122,7 @@ user.name = "Pete"; // Error: Cannot assign to read only property 'name'...
122
122
123
123
Now no one can change the name of our user, unless they apply their own `defineProperty` to override ours.
124
124
125
-
```smart header="Errors appear only in use strict"
125
+
```smart header="Errors appear only in strict mode"
126
126
In the non-strict mode, no errors occur when writing to read-only properties and such. But the operation still won't succeed. Flag-violating actions are just silently ignored in non-strict.
Copy file name to clipboardExpand all lines: 1-js/11-async/05-promise-api/article.md
+6-7
Original file line number
Diff line number
Diff line change
@@ -112,7 +112,7 @@ Promise.all(requests)
112
112
));
113
113
```
114
114
115
-
A bigger example with fetching user information for an array of github users by their names (or we could fetch an array of goods by their ids, the logic is same):
115
+
A bigger example with fetching user information for an array of GitHub users by their names (we could fetch an array of goods by their ids, the logic is same):
**If any of the promises is rejected, `Promise.all` immediately rejects with that error.**
137
+
**If any of the promises is rejected, the promise returned by `Promise.all` immediately rejects with that error.**
138
138
139
139
For instance:
140
140
@@ -155,10 +155,10 @@ If one promise rejects, `Promise.all` immediately rejects, completely forgetting
155
155
156
156
For example, if there are multiple `fetch` calls, like in the example above, and one fails, other ones will still continue to execute, but `Promise.all` don't watch them any more. They will probably settle, but the result will be ignored.
157
157
158
-
`Promise.all` does nothing to cancel them, as there's no concept of "cancellation" in promises. In [another chapter](fetch-abort) we'll cover `AbortController` that aims to help with that, but it's not a part of the Promise API.
158
+
`Promise.all` does nothing to cancel them, as there's no concept of "cancellation" in promises. In [another chapter](info:fetch-abort) we'll cover `AbortController` that can help with that, but it's not a part of the Promise API.
159
159
```
160
160
161
-
````smart header="`Promise.all(...)` allows non-promise items in `iterable`"
161
+
````smart header="`Promise.all(iterable)` allows non-promise \"regular\" values in `iterable`"
162
162
Normally, `Promise.all(...)` accepts an iterable (in most cases an array) of promises. But if any of those objects is not a promise, it's wrapped in `Promise.resolve`.
163
163
164
164
For instance, here the results are `[1, 2, 3]`:
@@ -173,8 +173,7 @@ Promise.all([
173
173
]).then(alert); // 1, 2, 3
174
174
```
175
175
176
-
So we are able to pass non-promise values to `Promise.all` where convenient.
177
-
176
+
So we are able to pass ready values to `Promise.all` where convenient.
178
177
````
179
178
180
179
## Promise.allSettled
@@ -289,4 +288,4 @@ There are 5 static methods of `Promise` class:
289
288
- `value` (if fulfilled) or `reason` (if rejected).
290
289
5. `Promise.race(promises)` -- waits for the first promise to settle, and its result/error becomes the outcome.
291
290
292
-
Of these five, `Promise.all/allSettled` are the most common in practice.
291
+
Of these five, `Promise.all` is probably the most common in practice.
Copy file name to clipboardExpand all lines: 1-js/11-async/07-microtask-queue/article.md
+6-6
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ That's strange, because the promise is definitely done from the beginning.
21
21
22
22
Why did the `.then` trigger afterwards? What's going on?
23
23
24
-
## Microtasks
24
+
## Microtasks queue
25
25
26
26
Asynchronous tasks need proper management. For that, the standard specifies an internal queue `PromiseJobs`, more often referred to as "microtask queue" (v8 term).
27
27
@@ -68,7 +68,7 @@ let promise = Promise.reject(new Error("Promise Failed!"));
Now, if you run it, we'll see `Promise Failed!` message first, and then `caught`.
96
+
Now, if you run it, we'll see `Promise Failed!` message first, and then `caught`.
97
97
98
-
If we didn't know about microtasks, we could wonder: "Why did `unhandledrejection`happen? We did catch the error!".
98
+
If we didn't know about microtasks queue, we could wonder: "Why did `unhandledrejection`handler run? We did catch the error!".
99
99
100
-
But now we do know that `unhandledrejection` is generated when the microtask queue is complete: the engine examines promises and, if any of them is in "rejected" state, then the event triggers.
100
+
But now we understand that `unhandledrejection` is generated when the microtask queue is complete: the engine examines promises and, if any of them is in "rejected" state, then the event triggers.
101
101
102
-
...By the way, the `.catch` added by `setTimeout` also triggers, of course it does, but later, after `unhandledrejection` has already occurred.
102
+
In the example above, `.catch` added by `setTimeout` also triggers, but later, after `unhandledrejection` has already occurred, so that doesn't change anything.
Copy file name to clipboardExpand all lines: 2-ui/1-document/09-size-and-scroll/article.md
+5-3
Original file line number
Diff line number
Diff line change
@@ -39,7 +39,9 @@ So, without scrollbar the content width would be `300px`, but if the scrollbar i
39
39
```
40
40
41
41
```smart header="The `padding-bottom` area may be filled with text"
42
-
Usually paddings are shown empty on illustrations, but if there's a lot of text in the element and it overflows, then browsers show the "overflowing" text at `padding-bottom`, so you can see that in examples. Still, the padding is set in further examples, unless explicitly specified otherwise.
42
+
Usually paddings are shown empty on illustrations, but if there's a lot of text in the element and it overflows, then browsers show the "overflowing" text at `padding-bottom`.
43
+
44
+
That's a note to avoid confusion, as `padding-bottom` is set in further examples, unless explicitly specified otherwise.
43
45
```
44
46
45
47
## Geometry
@@ -66,7 +68,7 @@ That's the nearest ancestor, that satisfies following conditions:
66
68
2. or `<td>`, `<th>`, `<table>`,
67
69
2. or `<body>`.
68
70
69
-
In most practical cases `offsetParent` is exactly the nearest ancestor, that is CSS-positioned. And `offsetLeft/offsetTop` provide x/y coordinates relative to its upper-left corner.
71
+
Properties `offsetLeft/offsetTop` provide x/y coordinates relative to its upper-left corner.
70
72
71
73
In the example below the inner `<div>` has `<main>` as `offsetParent` and `offsetLeft/offsetTop` shifts from its upper-left corner (`180`):
72
74
@@ -105,7 +107,7 @@ For our sample element:
105
107
-`offsetWidth = 390` -- the outer width, can be calculated as inner CSS-width (`300px`) plus paddings (`2 * 20px`) and borders (`2 * 25px`).
106
108
-`offsetHeight = 290` -- the outer height.
107
109
108
-
````smart header="Geometry properties for not displayed elements are zero/null"
110
+
````smart header="Geometry properties are zero/null for elements that are not displayed"
109
111
Geometry properties are calculated only for displayed elements.
110
112
111
113
If an element (or any of its ancestors) has `display:none` or is not in the document, then all geometry properties are zero (or `null` if that's `offsetParent`).
0 commit comments