Window, BOM, DOM, Node, and HTML Parser Explained in Depth

1. HTML Parser

The HTML parser in JavaScript is responsible for reading and interpreting HTML code, converting it into a structured format—usually a DOM (Document Object Model) tree—that can be manipulated by JavaScript. This process, known as parsing, is essential for browsers and tools to understand and work with HTML content effectively.

Key Points:

Example:


// This code relies on the DOM created by the HTML parser
console.log(document.body.children[0].innerText); // Logs text of first child of body
            

2. Document Object Model (DOM)

The DOM is a programming interface that represents the structure of an HTML or XML document as a tree of objects. It allows you to read, manipulate, and modify the content and structure of web pages using JavaScript.

Key Points:

Example:


// Changes heading text using DOM
document.querySelector('h1').innerText = 'Welcome to DOM World!';
            

4. Browser Object Model (BOM)

The Browser Object Model (BOM) provides JavaScript access to browser-specific features like navigation, screen size, and browser history. It is separate from the content of the page.

Key Points:

Example:


console.log('Current URL:', window.location.href);
console.log('Browser Info:', window.navigator.userAgent);
            

5. Window Object

The Window object is the global object for JavaScript in the browser. Every global variable or function is actually a property or method of window.

Key Points:

Example:


window.alert('Hello from the Window object!');
console.log('Window dimensions:', window.innerWidth, 'x', window.innerHeight);
            

6. Comparison Table: Window vs BOM vs DOM vs HTML Parser

Aspect Window BOM DOM HTML Parser
Definition Global object for browser tab Browser feature interface Page content interface Engine to convert HTML to DOM
Contains DOM + BOM navigator, screen, history document, elements HTML to tree converter
Use Case Global browser-level control Browser-related tasks Manipulate HTML content Builds DOM from HTML
Examples alert(), setTimeout() window.location.href document.querySelector() Internal process (not accessed directly)