Custom Events — JS Technical Interview Questions & Answers
Dispatching your own events with CustomEvent.
Custom Events
- Custom Events (js) is a JS topic. In plain words you use it for a short Custom Events js example in a script in the browser. Don’t start with a slogan — start with that picture.
- Smallest example: the smallest Custom Events js example you can type. Type it, run it, and say what you see. If you can do that from memory, you know Custom Events (js).
- From the example next to this theory: Dispatching your own events with CustomEvent.
- Trap: only saying “Custom Events js” with no example. Fix that before you talk about advanced JS.
- Viva: what is Custom Events (js)? Then show the smallest Custom Events js example you can type. Then name the trap.
Technical Interview Tip: What is Custom Events (js)? Show this: the smallest Custom Events js example you can type. Trap: only saying “Custom Events js” with no example.
Code Examples for Custom Events
Custom Events — 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; } }));Custom Events — listeners react to events; delegation handles many children from one parent; preventDefault stops default browser action.
How to Explain Custom Events to an Interviewer
What is Custom Events (js)?
Used for a short Custom Events js example a script in the browser Not just the heading
Give one small example of Custom Events (js).
the smallest Custom Events js example you can type Dispatching your own events with CustomEvent
What mistake do beginners make with Custom Events (js)?
only saying “Custom Events js” with no example Show the fix
Where do you use Custom Events (js)?
a script in the browser a short Custom Events js example