InterviewStack.io LogoInterviewStack.io

Document Object Model and Event Handling Questions

Comprehensive coverage of using JavaScript to build interactive web interfaces by manipulating the Document Object Model and responding to user and browser events. Core skills include element selection and traversal, reading and updating content and attributes, creating and removing nodes, and making efficient, performance conscious updates to minimize layout and paint costs. Event handling topics cover registering and removing event listeners, the structure of event objects, the difference between event target and current target, propagation models including capturing and bubbling, stopping propagation and preventing default behavior, event delegation for scalable handlers, and handling common event types such as click, input, change, submit, keyboard, pointer, touch, and drag and drop. Also included are patterns for state management in vanilla JavaScript so that user interactions update the interface predictably, controlled versus uncontrolled form patterns in component frameworks such as React, and cross component event flows and architecture for more senior assessments. Familiarity with browser application programming interfaces commonly used with interactive features such as Intersection Observer, fetch for network requests, and local storage is expected. Asynchronous JavaScript fundamentals are part of this topic, including the event loop, callbacks, promises, and the async and await syntax. Defensive and performance practices are emphasized, including debouncing and throttling, batching and minimizing Document Object Model mutations, avoiding memory leaks by cleaning up listeners and references, handling dynamically inserted content, and accessibility concerns such as keyboard navigation, focus management, and form validation.

EasyTechnical
24 practiced
In plain JavaScript (ES6+), write a small function that attaches a click listener to a button element which toggles the 'is-active' class and the aria-pressed attribute. The handler should be removable later; show how you would register and then remove the listener cleanly for multiple buttons on the page.
MediumTechnical
18 practiced
Explain common causes of memory leaks in frontend applications related to DOM and event handling (for example lingering event listeners, timers, closures holding DOM references, MutationObservers). Describe strategies and patterns to detect and fix these leaks and show a short vanilla JS code pattern to remove listeners when a component is destroyed.
EasyTechnical
25 practiced
Explain differences between innerText, textContent, innerHTML, and outerHTML for reading and updating DOM content. Discuss security implications (XSS) when using innerHTML with user-provided content and performance differences between these APIs.
HardTechnical
22 practiced
Explain advanced strategies for batching DOM mutations and repaints for high-frequency updates such as animations or live data streams. Cover requestAnimationFrame usage, separating reads from writes, double buffering, and when offscreen rendering (canvas or layers) or CSS properties like will-change are appropriate.
EasyTechnical
24 practiced
Describe the differences between event.target, event.currentTarget, and this inside an event listener. Provide a concrete example (for example a container with nested elements) where these values differ and explain how to use event.currentTarget to reliably reference the element the handler is bound to.

Unlock Full Question Bank

Get access to hundreds of Document Object Model and Event Handling interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.