Browser & Frontend Runtime
Event loop: multiple-choice review
Six questions that cut across the whole unit. Each one mirrors a call you make in a real performance incident — not a definition to recite, but which queue a primitive lands in, and what that costs the next frame.
Confirm you can connect queue semantics, the render step, timer throttling, starvation, and cross-runtime differences — the synthesis the individual lessons built toward.
Inside a click handler you call setTimeout(t, 0) then queueMicrotask(m), then the handler returns. In what order do t and m run relative to the next paint?
A click handler runs for 400 ms. Which of these keeps working during the block, and why?
You must do 200 ms of work without freezing input. You try await Promise.resolve() between chunks and the page still locks up. Why, and what actually yields?
A background tab runs setInterval(poll, 1000). After several minutes hidden, how often does the callback fire, and what compounds with this?
A search input shows INP of 410 ms. The Long Tasks API logs a 312 ms task but only attributes it to 'same-origin'. What is the right next instrument and why?
A library tested only in Node chains process.nextTick(a) then Promise.resolve().then(b) and relies on a running before b. Ported to the browser via a nextTick polyfill, the ordering flips. Why?
The through-line across the unit is one decision: which queue does this primitive land in, and what does that cost the next frame. Microtasks (promise callbacks, queueMicrotask, MutationObserver) drain before rendering and starve it if they self-schedule; tasks (setTimeout, MessageChannel, input dispatch) yield to rendering but pay clamps and throttling; rAF runs only on a frame boundary. Diagnose user-perceived latency with INP, attribute it with LoAF plus sourcemaps, and remember that Node reorders all of this with process.nextTick sitting above microtasks.