An async function is a function declared with the async keyword which enables asynchronous, promise-based behavior to be written in a cleaner style by avoiding promise chains. These functions can contain zero or more await expressions.
Let’s take a below async function example:
1 2 3 4 5 6 | async function logger() { let data = await fetch('http://someapi.com/users'); // pause until fetch returns console.log(data) } logger(); |
It is basically syntax sugar over ES2015 promises and generators.
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.