The DOM and events · core
Event flow: capture, target, bubble
An event travels down from window to the target (capture), fires on the target, then bubbles back up; stopPropagation stops the travel, stopImmediatePropagation also stops other listeners on the same element, and preventDefault only cancels the browser's default action.
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
- addEventListener(type, fn, { capture: true }) listens during the capture phase; default is bubble.
- event.target is where the event started; event.currentTarget is the element whose listener is running now.
- stopPropagation: no more elements on the path. stopImmediatePropagation: also no more listeners on this element.
- preventDefault cancels the default action (link navigation, form submit, checkbox toggle) but does not stop propagation.
- Some events don't bubble (focus, blur, mouseenter); use focusin/focusout for delegation.
The red pen
Common traps: mistake → fix
Mistake: "preventDefault stops bubbling"
Fix: it only cancels the default action.
Mistake: "target and currentTarget are the same"
Fix: they differ whenever the listener is on an ancestor.
Easy to hard
Questions interviewers ask, easy to hard
- Explain capture and bubble with the order of logs for nested elements.
- stopPropagation vs stopImmediatePropagation vs preventDefault?
- Which events don't bubble?
Practise
Practise with these questions
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.