Output prediction · Write code
Event propagation order
Practise this out loud
Say your answer out loud to an AI interviewer that follows up, and get a score for it.
Practise by voiceThe interviewer asks
Clicking the button: what order do the logs appear in?
<div id="outer"><button id="btn">Click</button></div>
<script>
outer.addEventListener('click', () => console.log('outer bubble'));
outer.addEventListener('click', () => console.log('outer capture'), true);
btn.addEventListener('click', () => console.log('btn bubble'));
btn.addEventListener('click', () => console.log('btn capture'), true);
</script>
Then
Follow-ups the interviewer asks next
- What if
btn capturecallsstopPropagation()?stopImmediatePropagation()? - Which events don't bubble (
focus,blur,mouseenter), and what are their bubbling alternatives? - The
once,passiveandsignallistener options.
The answer
What a strong answer covers
outer capture,btn capture,btn bubble,outer bubble- Modern browsers fire capture listeners at the target before non-capture ones (a 2021 spec change; older browsers used registration order)
The red pen
Common traps
Avoid:"the target's listeners run in registration order", which is pre-2021 behaviour.
Practise this out loud
Say your answer out loud to an AI interviewer that follows up, and get a score for it.
Practise by voicePractise questions like this out loud
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.