The DOM: interview questions
Walking and searching the element tree, events and delegation, and building small DOM utilities. 26 questions from the Front End Interview Handbook. 8 have our own answer, built up from basic to advanced, with code that is proved by tests (how answers are checked).
- DOM APIs:
document.getElementByClassName(),document.getElementByTagName()The DOM · basicJavaScript codingcheckednot tried - Generate table of contents/outline from a HTML page (similar to Google Docs autogenerated outline).The DOM · advancedJavaScript codingcheckednot tried
- React-like VDOM but instead of creating DOM nodes, output an HTML string given an input object with
typeandattributes.React, The DOM · reported at ByteDance/TikTokJavaScript codingcheckednot tried - Implement
getByClassName()andgetByClassnameHierarchy()The DOM · reported at DropboxJavaScript codingcheckednot tried - DFS on HTML nodes.The DOM, Data structures and algorithms · reported at GoogleJavaScript codingcheckednot tried
- Write a
getElementsByClassNamefunction.The DOM · reported at LinkedInJavaScript codingcheckednot tried - Find the identical DOM node in two identical trees: given a node in one tree, locate the equivalent node in the other tree by reference. Efficient solution: walk up via
parentNode, record the path, then replay the path in the other tree (avoids touching unrelated nodes vs. DFS/BFS).The DOM · reported at MetaJavaScript codingcheckednot tried - Read HTML form data and construct a JSON object.The DOM, HTML · reported at RedditJavaScript codingcheckednot tried
- Explain event delegationThe DOMQuizhandbooknot tried
- Describe event bubbling.The DOMQuizhandbooknot tried
- Explain how a browser determines what elements match a CSS selector.The DOM, CSS and layoutQuizhandbooknot tried
- Describe pseudo-elements and discuss what they are used for.CSS and layout, The DOMQuizhandbooknot tried
- What's the difference between a
relative,fixed,absoluteandstatically positioned element?The DOM, CSS and layoutQuizhandbooknot tried - What are empty elements in HTML?The DOM, HTMLQuizhandbooknot tried
- Implement a function
getElementsByStyle(property, value)that returns all elements in the DOM that match that style.The DOM · reported at AmazonCodingno answer yetnot tried - Fetch todos from an API and render 20 at a time. The dummy API takes params to control how many you get. Use
fetchwith no helper libraries; brush up on creating, appending, and removing DOM elements.The DOM, UI components · reported at AtlassianUser interface codingno answer yetnot tried - "Language proficiency" round: build an in-memory comment service in TypeScript. Prep covers DOM mutations, event handling, async, and core JavaScript fundamentals. They send a starter pack of HTML/CSS/JS files ahead of time — set up your TypeScript environment before the interview.Async, promises and timers, The DOM · reported at CanvaJavaScript codingno answer yetnot tried
- Build a chat web app (Discord-style). Some candidates are asked the full-stack version (React + Node.js with WebSockets); front-end-only candidates have been asked a UI variant of the same.The DOM, Data structures and algorithms · reported at DiscordUser interface codingno answer yetnot tried
- Prepare to debug and refactor an existing JavaScript/Node.js application, as outlined to an applicant before their round. The stated concerns were reliability, security, and maintainability.The DOM, Security · reported at eBayJavaScript codingno answer yetnot tried
- Design a webpage which can auto load new posts when you reach the bottom of the page by using JavaScript. You may use AJAX and JavaScript event listeners.The DOM, Frontend system design · reported at GoogleUser interface codingno answer yetnot tried
- Difference between event bubbling and capturing?The DOM · reported at LinkedInQuizno answer yetnot tried
- What is event delegation?The DOM · reported at LinkedInQuizno answer yetnot tried
- Sticky ads on scroll: implement an ad element that follows the user as they scroll. Throttle is preferred over debounce here because the ad must reposition during the scroll, not after it ends.Async, promises and timers, The DOM · reported at MetaUser interface codingno answer yetnot tried
- What is DOM?The DOM · reported at MicrosoftQuizno answer yetnot tried
- Explain why the React implementation works, including state updates, DOM behavior, and CSS text rendering.The DOM, React · reported at OpenAICodingno answer yetnot tried
- Tech screen: vanilla JavaScript bug-fix. You are given a working but buggy file with several classes (the example reported was a shopping cart with review comments and a 5-star rating widget). One by one the interviewer tells you what the bug is (e.g. "the 5-star widget lets you review more than once") and you fix it. Bugs cover state manipulation, array handling, DOM updates. Open book — you can search online. At the end, they ask for an overall code review of the file: how you would have implemented the whole thing differently, what you'd change about data, state, and performance.Arrays and objects, The DOM · reported at SquarespaceUser interface codingno answer yetnot tried