JavaScript · Senior · Question 2 of 75

What happens to the page?

function loop() {
  Promise.resolve().then(loop);
}
loop();

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.

Further reading

Problem with a question

JavaScript · Senior · question 2

Test yourself

Take the JavaScript · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz