Javascript: Async/Await

PHOTO EMBED

Mon Aug 29 2022 20:02:26 GMT+0000 (UTC)

Saved by @marcopinero #javascript

function resolveAfter2Seconds() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve('resolved');
    }, 2000);
  });
}

async function asyncCall() {
  console.log('calling');
  const result = await resolveAfter2Seconds();
  console.log(result);
  // expected output: "resolved"

asyncCall();
content_copyCOPY

How to call a function using async/await in javascript.