What’s the use of Await function with an example
Anónimo
await is a new operator used to wait for a promise to resolve or reject. It can only be used inside an async function. function testRunafter2Sec() { return new Promise(resolve => { setTimeout(() => { resolve('test'); }, 2000); }); } async function msg() { const msg = await testRunafter2Sec(); console.log('Message:', msg); } msg(); // output: test -->after 2 second