JavaScript · Senior · Question 59 of 75
Why can this code freeze the page even though it uses promises?
function loop() { Promise.resolve().then(loop); }
loop();- ✓Correct answer: Each microtask schedules another, so the microtask queue never empties and rendering never happens
- 2Promises run on a separate thread and overload the CPU
- 3It doesn't freeze; promises yield to rendering
Explanation
The browser renders only between macrotasks after the microtask queue drains. Use setTimeout, MessageChannel or scheduler.yield() to give rendering a chance.