Do you know what will be the output of this code?
JavaScript
console.log("A");
setTimeout(() => console.log("B"), 0);
Promise.resolve().then(() => console.log("C"));
console.log("D");
Show answer and explanation
The answer is A D C B.
Synchronous code runs first: A, D. Then the event loop empties the microtask queue (promise callbacks): C. Only then does it run the next task (the timer): B.