Browser - Document variable (DOM) - Javascript

1 - About

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

3 - Example

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

4 - 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,..)
}

Data Science
Data Analysis
Statistics
Data Science
Linear Algebra Mathematics
Trigonometry

Powered by ComboStrap