Skip to the page

Output prediction · Write code

Event propagation order

The 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

  1. What if btn capture calls stopPropagation()? stopImmediatePropagation()?
  2. Which events don't bubble (focus, blur, mouseenter), and what are their bubbling alternatives?
  3. The once, passive and signal listener 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 voice

Practise 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.

Start your free interview