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);
Notice that the console prints 2 before the “Hello World”. This is due to the usage of the await keyword.
|