Async Await Example

Use async and await for cleaner asynchronous code.

Preview

Code

<script>
function delay(){
  return new Promise(resolve => {
    setTimeout(()=>resolve("Done"),1000);
  });
}

async function run(){
  let result = await delay();
  console.log(result);
}

run();
</script>

More JS Asynchronous Examples (7)