Skip to content

Latest commit

 

History

History
34 lines (26 loc) · 1.79 KB

File metadata and controls

34 lines (26 loc) · 1.79 KB

Promise Order easy #javascript #promise #event loop

by Pawan Kumar @jsartisan

Take the Challenge

What will be order of console logs in the following code?

console.log(1);
const promise = new Promise((resolve) => {
  console.log(2);
  resolve();
  console.log(3);
});

console.log(4);

promise
  .then(() => {
    console.log(5);
  })
  .then(() => {
    console.log(6);
  });

console.log(7);

setTimeout(() => {
  console.log(8);
}, 10);

setTimeout(() => {
  console.log(9);
}, 0);

Back Share your Solutions Check out Solutions