Systems-Level CS in the Browser: A Frontend Engineer's Guide to Reconciliation, the Event Loop, Race Conditions & Hashing
A 40-question deep dive built to help frontend engineers better understand algorithms by grounding classic computer-science ideas in browser behavior you can actually observe. Four systems-level topics: the Virtual DOM as a tree-diff algorithm (reconciliation heuristics, list keys, Myers diff), the event loop as a scheduling problem (micro- vs. macro-tasks, requestAnimationFrame, task starvation, cooperative yielding), client-side race conditions and cancellation (out-of-order responses, stale closures, AbortController), and identity, equality & hashing (=== vs. value equality, structural sharing, content hashes). Every "predict the output" answer was executed in Node to confirm it, and every answer links to MDN, the React docs, Wikipedia, or a primary source so you can verify it yourself.
Questions
- Not answered. The Virtual DOM is often sold as a performance trick. From a CS standpoint, what problem is React's reconciler actually solving?
- Not answered. The best known algorithms for the general tree-diff problem run in about O(n³). How does React get reconciliation down to O(n)?
- Not answered. Between two renders, an element at the same position changes type — a
<div>becomes a<span>. What does React do? - Not answered. You render a list of
<input>s withkey={index}. The user types into the first input, then you prepend a new item to the array. What does the user observe? - Not answered. Same list, but now
key={item.id}with stable ids. You prepend a new item. What actually mounts? - Not answered.
git diffand many list-diffing libraries are built on Myers' diff algorithm. What does it compute, and at what cost? - Not answered. Which statements about React keys are true? Select all that apply.
- Not answered. React's O(n) reconciliation rests on deliberately unsound heuristics. Which of these are assumptions React really makes? Select all that apply.
- Not answered. An app uses
key={index}for a reorderable list of rows, each holding local state (an open/closed toggle, a focused input). Which bugs are plausible? Select all that apply. - Not answered. The state-of-the-art algorithms for the general tree-diff problem run in roughly O(n^k) time, and React's reconciliation docs cite that exponent as the reason it uses heuristics instead. What integer is k?
- Not answered. After the currently running task finishes, how does the event loop treat the microtask queue?
- Not answered.
Promise.resolve().then(f)andsetTimeout(g, 0)both mean "do this later." Which runs first, and why? - Not answered. Where does a
requestAnimationFramecallback sit relative to microtasks andsetTimeout? - Not answered. What sets
requestIdleCallbackapart fromsetTimeoutandrequestAnimationFrame? - Not answered. Why can an endlessly self-rescheduling microtask freeze the page, while an endlessly self-rescheduling
setTimeoutdoes not? - Not answered. Which of these schedule a microtask (rather than a macrotask)? Select all that apply.
- Not answered. React's concurrent renderer "time-slices" long work so the page stays responsive. Which statements about cooperative yielding on the main thread are true? Select all that apply.
- Not answered. Which statements about the browser event loop are true? Select all that apply.
- Not answered. Predict the output. How many lines are logged before
"setTimeout"appears? - Not answered. Predict the output. Type the four numbers in the exact order they are logged, with no spaces (e.g.
1234). - Not answered. A search box fires a request on every keystroke. The user types
react. Results forreasometimes appear after results forreact, overwriting them. What is the root cause? - Not answered. Without cancelling anything, what's the simplest correct fix for out-of-order search responses?
- Not answered. What does
AbortControlleractually do when you callcontroller.abort()on afetchstarted with{ signal: controller.signal }? - Not answered. A
setIntervalcallback created inside a component keeps loggingcountas0, even thoughcountvisibly increments on screen. Why? - Not answered. The React docs' data-fetching effect declares
let ignore = falseand returns() => { ignore = true; }. How does that prevent a race? - Not answered. A "Pay" button fires a POST; the user double-clicks and the network retries on flaky wifi. Why does making the endpoint idempotent (e.g. with an idempotency key) matter?
- Not answered. Which statements about client-side race conditions are true? Select all that apply.
- Not answered. You're fixing a "type fast, see the wrong results" bug in a search component. Which approaches correctly stop stale results from winning? Select all that apply.
- Not answered. Which fixes correctly stop a
setInterval/ event callback from reading a stalecount? Select all that apply. - Not answered. Predict the output. This logs the same number three times — type that number.
- Not answered. Why is
{} === {}falsewhile2 === 2istrue? - Not answered. A memoized child re-renders every time its parent does, even though "nothing changed." The parent passes
style={{ margin: 0 }}. Why does this defeatReact.memo? - Not answered. Where does
Object.is(a, b)differ froma === b? - Not answered. Immer (and persistent data structures generally) return a new state object on every update but reuse untouched subtrees. Why is that the perfect partner for
===-based change detection? - Not answered. Content hashing shows up as
app.8f3b2c.jsin build output, asintegrity="sha384-…"on a<script>, and as Quizbun's own per-Question Content hash. What single property makes hashing useful in all three? - Not answered. Why can't a hash give a guaranteed-unique fingerprint for arbitrary content, and when does it matter?
- Not answered. Which statements about shallow vs deep equality are true? Select all that apply.
- Not answered. Which of these create a new reference on every render, potentially busting memoization or
useEffectdeps? Select all that apply. - Not answered. Which statements about hashing and content-addressing are true? Select all that apply.
- Not answered. How many distinct object references does this array contain — that is, how many of its elements are
!==each other?