Sobes.tech
Junior — Senior

Determining the output sequence in the console

livecode

Task condition

Determine the order in which the values will be printed to the console, considering synchronous calls, microtasks (Promise.then, .catch), and macrotasks (setTimeout).

console.log(1);

setTimeout(() => console.log(2));

Promise.reject(3)
  .catch(console.log)
  .then(() => console.log(7));

new Promise(resolve => setTimeout(resolve))
  .then(() => console.log(4));

Promise.resolve(5)
  .then(console.log)
  .then(() => console.log(8));

console.log(6);