DEV Community

Tal Rofe
Tal Rofe

Posted on • Updated on

Can you answer this Javascript question?

Can you tell what would be the following output of these snippets?

const promise = new Promise((resolve, reject) => {                                                                       20/10/2021
  console.log("YAZIF");

  setTimeout(() => resolve(), 0);
});

new Promise((resolve, reject) => {
  console.log("Yazof");

  setTimeout(() => resolve(), 0);
}).then(() => console.log(2));

console.log("CHEDDAR");

promise.then(() => console.log(1));

Enter fullscreen mode Exit fullscreen mode

Verify your answer. Now, can you also answer this?

const promise = new Promise((resolve, reject) => {                                                                       20/10/2021
  console.log("YAZIF");

  resolve();
});

new Promise((resolve, reject) => {
  console.log("Yazof");

  resolve();
}).then(() => console.log(2));

console.log("CHEDDAR");

promise.then(() => console.log(1));
Enter fullscreen mode Exit fullscreen mode

Top comments (0)