0 votes
in JavaScript by
What is Await Function  in javscript?

1 Answer

0 votes
by

Await function is used to wait for the promise. It could be used within the async block only.

It makes the code wait until the promise returns a result.

Example 2: This example shows the basic use of the await keyword in JavaScript.

   
const getData = async () => {
    let y = await "Hello World";
    console.log(y);
}
 
console.log(1);
getData();
console.log(2);
Output
1
2
Hello World

Notice that the console prints 2 before the “Hello World”. This is due to the usage of the await keyword. 

...