DOM APIs & Browser Internals Questions
Understanding DOM traversal methods, manipulation, and performance considerations. Understanding the difference between innerHTML and textContent, element creation methods, fragment optimization. Event handling: event delegation, event bubbling and capturing, event listeners optimization. Knowing when DOM operations cause reflows and repaints. Understanding MutationObserver and other browser APIs.
MediumTechnical
39 practiced
Design a small JavaScript function that safely renders user-provided HTML that may include a limited set of tags (for example <b>, <i>, <a>). You cannot use third-party sanitizer libraries. Describe the whitelist approach, attribute filtering (for href, target, rel), and implement a safe insertion using DOMParser or programmatic element creation. Discuss remaining risks and trade-offs.
EasyTechnical
35 practiced
Compare element.innerText and element.textContent. Explain differences in behavior (layout-dependent versus raw text), performance implications when reading or setting each, cross-browser nuances, and examples that show different outputs when elements are hidden or have CSS affecting visibility.
EasyTechnical
59 practiced
Explain two approaches to determine if an element is visible in the viewport: polling with getBoundingClientRect inside scroll/resize handlers (with throttling/debouncing) and using IntersectionObserver. Compare performance, accuracy, and browser support, then provide example code for lazy-loading an image using both methods.
MediumTechnical
34 practiced
You have code that iterates a list of elements and alternates reading offsetHeight and then setting style.height on each iteration. Explain why this causes layout thrashing and poor performance. Provide a refactored implementation that separates reads from writes to avoid repeated reflows and explain the benefits of your approach.
EasyTechnical
44 practiced
Compare three DOM insertion approaches: document.createElement + appendChild, element.insertAdjacentHTML, and element.innerHTML = '...'. Describe differences in parsing, performance, how scripts in the inserted HTML are handled, and security trade-offs. Provide guidance on when to prefer programmatic creation versus HTML string insertion in interactive UI code.
Unlock Full Question Bank
Get access to hundreds of DOM APIs & Browser Internals interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.