ForgeFrontend — Prepare, Practice, Crack
Secure checkout
Lifetime access
Instant Drive delivery
Free updates forever

Prepare · Practice · Crack

What is event delegation and why is it useful?

Quick answer

Attach one listener to a parent and use event.target to handle events from many children — fewer listeners, works for dynamic elements.

In detail

Because events bubble, a single parent listener can handle clicks on any child. This saves memory (one listener instead of hundreds) and automatically covers elements added later. Check `event.target` (often with `closest()`) to find what was clicked.

list.addEventListener("click", (e) => {
  const item = e.target.closest("li");
  if (item) select(item.dataset.id);
});

Why interviewers ask this: A practical favourite — tests bubbling understanding.

This is 1 of 118+ questions in the JavaScript Interview Kit

Get every question with detailed answers, follow-ups and real code — plus coding challenges and a last-minute revision sheet. One-time payment, instant access.

⚡ Get the JavaScript Interview Kit → ₹299

Full kit

JavaScript Interview Kit · ₹299

Get it →