Javascript Async & Await
Opened this issue · 0 comments
sophryu99 commented
Async keyword
The word “async” before a function means one simple thing: a function always returns a promise. Other values are wrapped in a resolved promise automatically.
async function f() {
return 1
}
f().then(result => console.log(result));
Await keyword
However, this way of processing asynchronous functions can be unintuitive.
The “await” keyword provides a much clearer way to process asynchronous function. With “await”, you can process async functions just like synchronous ones.
async function f() {
return 1
}
let result = await f();
console.log(result)