0 votes
in JavaScript by
What is an async function in javascript?

1 Answer

0 votes
by

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,

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.

...