BOM: Browser Object Model

JavaScript is an object-based programming language, almost everything in JavaScript is an object(e.g. arrays, functions, etc). Similarly, the browser is also made up of objects.

To make our web app more interactive the browser provides us with a remarkable number of objects. e.g. window object, document object, etc.

The collection of objects that the browser makes available to you for use with JavaScript is generally called the BOM.

There are no official standards for the BOM, It is all dependent on the brand and the version of the browser.

However, modern browsers have implemented almost the same properties and methods for JavaScript interactivity.

Window Object

A window object is a root object of the Brower Object Model (BOM).

The window object is corresponding to the window of the browser. you may already have used the window object method e.g. alert(), prompt(), etc.

window.alert("Alert!");

//We can actually omit window keyword in order to use any property or method of the window object.

alert("Alert!");

All global variables become properties of the window objects and all global functions become methods of the window object. Remember global variables and functions are created using the var keyword. A function declaration also creates a global function.

var x = "Becomes the property of the window object";

console.log(window.x); // Becomes the property of the window object

var globalFun = function () {
    console.log("Becomes the method of the window object");
}

window.globalFun(); // Becomes the method of window object

The document object (of the HTML DOM) is a property of the window object.

If you have any doubts or questions, even if you want to give any suggestions please leave your comment.

If you find this article helpful please like this post, it will be huge motivation for me. THANK YOU FOR READING! ♥