Skip to content

Commit 15a3ed2

Browse files
committed
2 parents 659e9f2 + a64fb26 commit 15a3ed2

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

1-js/11-async/04-promise-error-handling/article.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ new Promise((resolve, reject) => {
7676

7777
The "invisible `try..catch`" around the executor automatically catches the error and treats it as a rejection.
7878

79-
That's so not only in the executor, but in handlers as well. If we `throw` inside a `.then` handler, that means a rejected promise, so the control jumps to the nearest error handler.
79+
This happens not only in the executor, but in its handlers as well. If we `throw` inside a `.then` handler, that means a rejected promise, so the control jumps to the nearest error handler.
8080

8181
Here's an example:
8282

@@ -90,7 +90,7 @@ new Promise((resolve, reject) => {
9090
}).catch(alert); // Error: Whoops!
9191
```
9292

93-
That's so not only for `throw`, but for any errors, including programming errors as well:
93+
This happens for all errors, not just those caused by the `throw` statement. For example, a programming error:
9494

9595
```js run
9696
new Promise((resolve, reject) => {
@@ -102,7 +102,7 @@ new Promise((resolve, reject) => {
102102
}).catch(alert); // ReferenceError: blabla is not defined
103103
```
104104

105-
As a side effect, the final `.catch` not only catches explicit rejections, but also occasional errors in the handlers above.
105+
The final `.catch` not only catches explicit rejections, but also occasional errors in the handlers above.
106106

107107
## Rethrowing
108108

@@ -120,7 +120,7 @@ new Promise((resolve, reject) => {
120120

121121
throw new Error("Whoops!");
122122

123-
}).catch(function(error) {
123+
}).catch(function(error) {
124124

125125
alert("The error is handled, continue normally");
126126

@@ -266,7 +266,7 @@ new Promise(function() {
266266

267267
In case of an error, the promise state becomes "rejected", and the execution should jump to the closest rejection handler. But there is no such handler in the examples above. So the error gets "stuck".
268268

269-
In practice, just like with a regular unhandled errors, it means that something terribly gone wrong, the script probably died.
269+
In practice, just like with a regular unhandled errors, it means that something has terribly gone wrong, the script probably died.
270270

271271
Most JavaScript engines track such situations and generate a global error in that case. We can see it in the console.
272272

2-ui/1-document/03-dom-navigation/article.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,12 @@ alert( document.documentElement.parentElement ); // null
237237

238238
In other words, the `documentElement` (`<html>`) is the root node. Formally, it has `document` as its parent. But `document` is not an element node, so `parentNode` returns it and `parentElement` does not.
239239

240-
Sometimes that matters when we're walking over the chain of parents and call a method on each of them, but `document` doesn't have it, so we exclude it.
240+
This loop travels up from an arbitrary element `elem` to `<html>`, but not to the `document`:
241+
```js
242+
while(elem = elem.parentElement) {
243+
alert( elem ); // parent chain till <html>
244+
}
245+
```
241246
````
242247
243248
Let's modify one of the examples above: replace `childNodes` with `children`. Now it shows only elements:

0 commit comments

Comments
 (0)