A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-40.js
1console.log('1');
2setTimeout(()=>console.log('2'),0);
3Promise.resolve().then(()=>{
4console.log('3');
5setTimeout(()=>console.log('4'),0);
6});
Async
Answer & explanation
Console output
1
3
2
4
Why
Synchronous "1" runs first. The first setTimeout("2") is registered, then the microtask runs before any timer, printing "3" and registering setTimeout("4"). When the event loop reaches the timer phase, "2" was registered earlier than "4", so timers fire in registration order: "2" then "4".