Loading the explainer…
Watch work move between the call stack, browser APIs, and the task queues as the runtime decides what executes next.
This is why a resolved promise can log before a zero-delay timer.
main() logs A, registers a timer, queues a promise reaction, then logs D. Statements execute inside the script; they are not separate stack frames.
console.log('A');
setTimeout(() => console.log('B'), 0);
Promise.resolve().then(() => console.log('C'));
console.log('D');What does this print?