0 votes
in JavaScript by
What is Async Function in Javascript?

1 Answer

0 votes
by

Async simply allows us to write promises-based code as if it was synchronous and it checks that we are not breaking the execution thread.

Async functions will always return a value. It makes sure that a promise is returned and if it is not returned then JavaScript automatically wraps it in a promise which is resolved with its value.

Example 1: In this example, we will see the basic use of async in JavaScript.

   
const getData = async () => {
    let data = "Hello World";
    return data;
}
 
getData().then(data => console.log(data));
...