Observers, workers and the platform · mid
ResizeObserver and MutationObserver
ResizeObserver reports element size changes (for components that adapt to their own width), and MutationObserver reports DOM changes (added nodes, attributes); both batch their callbacks.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- ResizeObserver entries give contentRect / contentBoxSize; use for charts and responsive components (container queries cover many CSS cases).
- MutationObserver(cb).observe(node, { childList, attributes, subtree }); callbacks run as microtasks after the changes.
- Avoid infinite loops: changing the observed thing inside the callback can trigger it again.
The red pen
Common traps: mistake → fix
Mistake: "MutationObserver fires synchronously for each change"
Fix: it batches records and runs as a microtask.
Easy to hard
Questions interviewers ask, easy to hard
- When do you need ResizeObserver instead of window resize?
- What is MutationObserver used for?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.