Skip to primary content
Web Technical Prep

Modern JavaScript Technical Interview Questions & Answers

Ace JavaScript interviews: Closures, Event Delegation, Prototypes, Promise.all vs Promise.allSettled, and the Event Loop.

Question 1

What is Event Delegation in JavaScript and why is it useful for performance?

Event delegation is a pattern of handling events at a parent element instead of attaching listeners to multiple child elements.

Event delegation relies on the mechanism of event bubbling: when an event occurs on a DOM element, it bubbles upward through all its parent ancestors in the DOM tree. By attaching a single event listener to a common ancestor element and inspecting event.target, we can manage events for dozens or hundreds of child elements (including dynamic elements added in the future), dramatically lowering browser memory consumption.

Web
// Single listener on parent <ul> instead of 100 <li> listeners
document.getElementById('studentList').addEventListener('click', (event) => {
    const target = event.target.closest('li');
    if (target && target.dataset.id) {
        console.log("Selected Student ID:", target.dataset.id);
    }
});

In an infinite-scrolling feed rendering thousands of comment cards, attaching individual click handlers to each button crashes mobile browsers, whereas a single delegated parent listener remains lightning-fast.

Interviewer Pro Tip: Always use event.target.closest(selector) inside the listener to handle clicks on nested child elements like SVG icons or span text.
Common Candidate Mistake: Attaching individual event listeners inside a loop when rendering dynamic DOM items.

Related follow-up question: What is the difference between event bubbling and event capturing?

Mock Technical Interviews in Ghaziabad

Prepare for tier-1 company coding and system design rounds with face-to-face mock interview practice at C-60 R.K Tower, 3rd Floor, RDC, Ghaziabad.

Call 7503962162
Physical Training Center

Visit Our Ghaziabad Training Center

Join classroom batches, attend interactive lab sessions, code with mentors, and take advantage of our high-speed dev workstations.

Campus Address:
C-60 R.K Tower, 3rd Floor, RDC, Ghaziabad, Ghaziabad, Uttar Pradesh
Direct Counseling Helpline:
Call 7503962162
Get Google Maps Directions Call Now: 7503962162 Explore Ghaziabad Training Hub
Call 7503962162 Get Course Details