JS Coding Questions Logo
JS Coding Questions
#410💼 Interview💻 Code

What is an async function

Advertisement

728x90

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,

javascript
1async function logger() {
2
3let data = await fetch("http://someapi.com/users"); // pause until fetch returns
4
5console.log(data);
6}
7
8logger();

It is basically syntax sugar over ES2015 promises and generators.

Advertisement

Responsive Ad
🎯 Practice NowRelated Challenge

JavaScript Coding Exercise 67

Test your knowledge with this interactive coding challenge.

Start Coding

Advertisement

728x90
410of476