Browser - Document variable (DOM) - Javascript


The document variable exists as a global variable and is provided by the browser (Not by the Javascript engine)

It represents the DOM document. Ie an interface to HTML document manipulation.

The DOM is a special object, often called a host object

The document variable is:

  • is a property of the window object
  • accessible globally through an alias


type = document.contentType;
console.log("The document type is "+type);

Browser Detection

The presence of the document object tells you that Javascript is running in a browser.

if (typeof document !== 'undefined') {
  // We are in a browser context
} else {
  // We are in a non-browser context (node,..)

Powered by ComboStrap