JavaScript · Senior · Question 2 of 75
What happens to the page?
function loop() {
Promise.resolve().then(loop);
}
loop();- ✓Correct answer: The page freezes: microtasks are added endlessly and rendering never happens
- 2Nothing bad: the browser manages to paint frames between microtasks
- 3
RangeError: Maximum call stack size exceededbecause of recursion
Explanation
The stack doesn't grow (each call is a separate microtask), so there's no overflow. But the microtask queue never empties, and the event loop never moves on to rendering or events. With setTimeout(loop) the page would stay responsive.