Sobes.tech
Junior — Senior

Determine which output will appear in the console when the code is executed

livecode

Task condition

You need to predict what values will be printed to the console after running the following JavaScript snippet. Pay attention to the order of execution of setTimeout, promises, and synchronous operators.

setTimeout(() => {
  console.log(1);
});

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

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

console.log(4);