JavaScript · Junior · Question 32 of 75
In what order are the numbers printed?
console.log(1);
setTimeout(() => console.log(2), 0);
Promise.resolve().then(() => console.log(3));
console.log(4);- ✓Correct answer:
1 4 3 2 - 2
1 2 3 4 - 3
1 4 2 3
Explanation
Synchronous code runs first (1, 4). Then the event loop runs all microtasks - promise callbacks (3) - and only then the next macrotask - the timer (2). setTimeout(fn, 0) doesn't mean "immediately".