In a browser, the document is:
The document is provided by the browser via its DOM webapi (Not by the Javascript engine, DOM is not a standard javascript library)
The document variable exists as a global variable
The document variable is:
type = document.contentType;
console.log("The document type is "+type);
The presence of the document object tells you that Javascript is running in:
if (typeof document !== 'undefined') {
// We are in a browser context
} else {
// We are in a non-browser context (node without dom library)
}