Await function

 function getNum() {

  return new Promise((resolve, reject) => {
    setTimeout(() => {
      let num = Math.floor(Math.random() * 10) + 1;
      console.log(num);
      resolve();
    }, 1000);
  });
}

async function demo() {
  await getNum();
  await getNum();
  await getNum();
  await getNum();
  getNum();
}

console.log(demo());




Comments

Popular posts from this blog

Callback Hell

TODO list with DOM

Refactoring callback hell code