Update article.md
Fixed typos and made grammar changes.
This commit is contained in:
parent
0a95d04b17
commit
585612033a
1 changed files with 4 additions and 4 deletions
|
@ -24,7 +24,7 @@ async function f() {
|
|||
f().then(alert); // 1
|
||||
```
|
||||
|
||||
...We could explicitly return a promise, that would be the same:
|
||||
...We could explicitly return a promise, that would be the same as:
|
||||
|
||||
```js run
|
||||
async function f() {
|
||||
|
@ -72,7 +72,7 @@ Let's emphasize: `await` literally makes JavaScript wait until the promise settl
|
|||
It's just a more elegant syntax of getting the promise result than `promise.then`, easier to read and write.
|
||||
|
||||
````warn header="Can't use `await` in regular functions"
|
||||
If we try to use `await` in non-async function, that would be a syntax error:
|
||||
If we try to use `await` in non-async function, there would be a syntax error:
|
||||
|
||||
```js run
|
||||
function f() {
|
||||
|
@ -250,7 +250,7 @@ async function f() {
|
|||
f();
|
||||
```
|
||||
|
||||
If we don't have `try..catch`, then the promise generated by the call of the async function `f()` becomes rejected. We can append `.catch` to handle it:
|
||||
If we don't have `try..catch` and a promise generated by the call of the async function `f()` becomes rejected. We can append `.catch` to handle it:
|
||||
|
||||
```js run
|
||||
async function f() {
|
||||
|
@ -263,7 +263,7 @@ f().catch(alert); // TypeError: failed to fetch // (*)
|
|||
*/!*
|
||||
```
|
||||
|
||||
If we forget to add `.catch` there, then we get an unhandled promise error (and can see it in the console). We can catch such errors using a global event handler as described in the chapter <info:promise-error-handling>.
|
||||
If we forget to add `.catch` there, then we get an unhandled promise error (viewable in the console). We can catch such errors using a global event handler as described in the chapter <info:promise-error-handling>.
|
||||
|
||||
|
||||
```smart header="`async/await` and `promise.then/catch`"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue