Event Delegation — JS Technical Interview Questions & Answers
Handling child events from a single parent listener.
Event Delegation
- Event Delegation (js) is a JS topic. In plain words you use it for a short Event Delegation js example in a script in the browser. Don’t start with a slogan — start with that picture.
- Smallest example: the smallest Event Delegation js example you can type. Type it, run it, and say what you see. If you can do that from memory, you know Event Delegation (js).
- From the example next to this theory: Handling child events from a single parent listener.
- Trap: only saying “Event Delegation js” with no example. Fix that before you talk about advanced JS.
- Viva: what is Event Delegation (js)? Then show the smallest Event Delegation js example you can type. Then name the trap.
Technical Interview Tip: What is Event Delegation (js)? Show this: the smallest Event Delegation js example you can type. Trap: only saying “Event Delegation js” with no example.
Code Examples for Event Delegation
Event Delegation — working example
// Browser delegation sketch:
// list.addEventListener("click", (e) => {
// if (e.target.matches("button.del")) {
// e.preventDefault();
// e.target.closest("li")?.remove();
// }
// });
// Runnable stand-in:
function onClick(e) {
if (e.target === "del") {
e.preventDefault?.();
return "removed";
}
return "ignored";
}
console.log(onClick({ target: "del", preventDefault() { this.ok = true; } }));Event Delegation — listeners react to events; delegation handles many children from one parent; preventDefault stops default browser action.
How to Explain Event Delegation to an Interviewer
What is Event Delegation (js)?
Used for a short Event Delegation js example a script in the browser Not just the heading
Give one small example of Event Delegation (js).
the smallest Event Delegation js example you can type Handling child events from a single parent listener
What mistake do beginners make with Event Delegation (js)?
only saying “Event Delegation js” with no example Show the fix
Where do you use Event Delegation (js)?
a script in the browser a short Event Delegation js example