FrontendDeveloper.in

JavaScript question detail

What is an async function

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.

Back to all JavaScript questions
Get LinkedIn Premium at Rs 399