JavaScript Interview Question #51

What is the DOM in JavaScript?

DOM, Events & Event Loop Fundamentals Mid-Level Intermediate

Quick Interview Answer

The DOM, or Document Object Model, is the browser's object representation of an HTML document. It exposes the page as a tree of nodes that JavaScript can read and modify.

Detailed Explanation

The DOM, or Document Object Model, is the browser's object representation of an HTML document. It exposes the page as a tree of nodes that JavaScript can read and modify.

Through the DOM, JavaScript can find elements, change text and attributes, add or remove elements, update styles, and respond to user interaction. The DOM is a browser API; it is not part of the core ECMAScript language itself.

Code Example

const heading = document.querySelector("h1");
heading.textContent = "JavaScript Interview Preparation";