Junior — Senior
Console output sequence considering event loop priorities
livecode
Task condition
It is necessary to determine the order in which values will be printed to the console. The execution priorities are taken into account: first synchronous code, then microtasks such as .then and .catch, and finally macrotasks like setTimeout.
console.log(1);
setTimeout(() => console.log(2));
Promise.reject(3).catch(console.log);
new Promise(resolve => setTimeout(resolve)).then(() => console.log(4));
Promise.resolve(5).then(console.log);
console.log(6);