Member-only story
Understanding async-await in JavaScript
Rules of thumb and examples for when and how to use async and await
async
and await
are extensions of promises. If you are not comfortable with the basics of promises, please spend some time understanding promises before reading further.
I am sure that many of you are using async
and await
already. But, I think it deserves a little more attention.
Here is a small test: If you can’t spot the problem with the below code, read on.
We will revisit this code block later, once we have gone through async-await
basics. As always, Mozilla docs is your friend. Especially check out the definitions.
From MDN:
“An asynchronous function is a function which operates asynchronously via the event loop, using an implicit
Promise
to return its result. But the syntax and structure of your code using async functions is much more like using standard synchronous functions.”