1. Computing

The Three Parts of JavaScript

Core, DOM, and BOM

By

Javascript and JScript each have the same three parts in their specifications. Understanding what these three parts are and what they do will assist you in understanding the relationship between JavaScript and JScript and also the reasons why the same code may behave differently in different browsers.

1. Basic Syntax

The core component of JavaScript is its syntax. Just as English has nouns and verbs, JavaScript has a syntax that dictates how the code is put together. In both JavScript and JScript, this syntax is based on the ECMAscript 262 standard. This standard defines how the core part of the language works.

This includes the definition of:

  • how to define your variables
  • how to perform calculations on those variables
  • how to set up loops and functions and
  • how to define objects

What this standard doesn’t define is how the script should interface with the web page and the browser.

2. The Document Object Model

The second component part of the language is the Document Object Model (DOM). This standard has been developed by the W3C and defines how JavaScript should communicate with the web page in order to extract content from the page for processing, add content to the page, as well as how to access the stylesheet for the page in order to change the appearance of the page. There are four different 'levels' in this set of standards.

The DOM0 'standards' are those methods that the browsers implemented prior to the W3C starting on writing the standards and which the browsers still support today.

The W3C has released three different sets of standards for interfacing with the web page each of which includes everything in the prior standard and which then adds further ways of interfacing with the page. These are known as DOM1, DOM2, and DOM3.

The DOM3 standard is considered to be the final version with no further additions to it being required. Most browsers currently support most or all of the DOM2 standard and small parts of the DOM3 standard. Internet Explorer is somewhat behind the other browsers and still has some gaps in its support for DOM2 although JScript does also provide some alternatives that provide similar functionality.

3. The Browser Object Model

The third and final component is the Browser Object Model which is how the scripts obtain information from the browser and pass information back to it.

For this part of the language there is no one actually co ordinating standards and so the browser writers can define their own interface. Most browsers other than Internet Explorer have copied the Firefox way of interfacing to the browser which simplifies the task somewhat.

Internet Explorer has two different ways of interfacing with the browser depending on whether the browser is being run in standards mode or quirks mode. This is determined by whether the page has a valid DOCTYPE statement as the first tag in the HTML file. Since quirks mode results in web pages looking different in different browsers you should always include a doctype as the first thing in your HTML. That will make it simpler to write code that provides equivalent processing for each browser.

  1. About.com
  2. Computing
  3. JavaScript
  4. Reference
  5. The Three Parts of JavaScript

©2014 About.com. All rights reserved.