JavaScript DOM Events Bubbling & Capturing Quiz
Answer 30 questions on event propagation phases, capturing basics, target behavior, bubbling mechanics, addEventListener options, stopping propagation, preventing default actions, and event delegation techniques.
Question 1
Which sequence describes the standard DOM event propagation order?
Question 2
Why is understanding all three phases important?
Question 3
What defines the capturing phase?
Question 4
When is capture-phase listening particularly helpful?
Question 5
What logs?
document.addEventListener('click', () => console.log('doc capture'), true)
document.body.addEventListener('click', () => console.log('body capture'), true)
document.body.addEventListener('click', () => console.log('body bubble'))
button.addEventListener('click', () => console.log('button bubble'))
button.click()Question 6
What is special about the target phase?
Question 7
Why might two listeners on the same target fire in different phases?
Question 8
What defines the bubbling phase?
Question 9
Which events do not bubble by default in browsers?
Question 10
What logs?
outer.addEventListener('click', () => console.log('outer bubble'))
inner.addEventListener('click', () => console.log('inner bubble'))
inner.click()
Question 11
What does the third argument (options) in addEventListener control?
Question 12
How does capture: true affect listener execution?
Question 13
What logs?
const log = []
parent.addEventListener('click', () => log.push('parent capture'), { capture: true })
parent.addEventListener('click', () => log.push('parent bubble'))
child.addEventListener('click', () => log.push('child bubble'))
child.click()
console.log(log)Question 14
What does event.stopPropagation do?
Question 15
How does stopImmediatePropagation differ?
Question 16
What logs?
outer.addEventListener('click', () => console.log('outer'))
inner.addEventListener('click', (event) => {
console.log('inner')
event.stopPropagation()
})
inner.click()Question 17
What does event.preventDefault do?
Question 18
Why might you pair preventDefault with custom validation?
Question 19
What logs?
document.querySelector('a').addEventListener('click', (event) => {
event.preventDefault()
console.log('link clicked but stayed on page')
})
document.querySelector('a').click()
Question 20
What is event delegation?
Question 21
Why is event delegation efficient for large lists?
Question 22
What logs?
list.addEventListener('click', (event) => {
if (event.target.matches('li')) {
console.log(event.target.dataset.id)
}
})
const li = document.createElement('li')
li.dataset.id = '42'
list.appendChild(li)
li.click()
Question 23
What logs?
const log = []
window.addEventListener('click', () => log.push('window capture'), true)
document.addEventListener('click', () => log.push('document bubble'))
const div = document.createElement('div')
div.addEventListener('click', () => log.push('div bubble'))
document.body.append(div)
div.click()
console.log(log)Question 24
What logs?
const parent = document.getElementById('parent')
const child = document.getElementById('child')
parent.addEventListener('click', () => console.log('parent capture'), { capture: true })
child.addEventListener('click', () => console.log('child capture'), { capture: true })
child.addEventListener('click', () => console.log('child bubble'))
parent.addEventListener('click', () => console.log('parent bubble'))
child.click()
Question 25
What logs?
const result = []
const handler = (label) => (event) => {
result.push(label)
if (label === 'child bubble 1') event.stopImmediatePropagation()
}
child.addEventListener('click', handler('child bubble 1'))
child.addEventListener('click', handler('child bubble 2'))
parent.addEventListener('click', handler('parent bubble'))
child.click()
console.log(result)Question 26
What logs?
form.addEventListener('submit', (event) => {
event.preventDefault()
console.log('blocked', event.defaultPrevented)
})
form.dispatchEvent(new Event('submit', { bubbles: true, cancelable: true }))
Question 27
What logs?
const panel = document.getElementById('panel')
panel.addEventListener('click', (event) => {
if (event.target.matches('button.remove')) {
console.log('removing', event.target.dataset.id)
}
})
const btn = document.createElement('button')
btn.className = 'remove'
btn.dataset.id = '7'
panel.append(btn)
btn.click()
Question 28
Why should passive: true be used on scroll or touch listeners?
Question 29
How does event.currentTarget differ from event.target in delegated handlers?
Question 30
Why should stopPropagation be used sparingly?
