The difference between document and Document

document is a global object provided by the browser, which represents the current HTML document and provides many methods and properties to access and manipulate the content of the document.

In JavaScript, the global object is window, and the document object is a property of the window object, so the object can be accessed through window.document or document for short.

The window object is the top-level container object of all other Web global objects, and it contains global variables and functions, as well as some other features and interfaces provided by the browser.

In a browser environment, variables and functions declared in the global scope automatically become properties and methods of the window object. For example, if a variable foo is declared in the global scope, it can be accessed as window.foo, or simply foo for short.


Document is an interface provided by the DOM API, which represents the Document Object Model (DOM) of the current HTML page.


Both have the same properties and methods. It is recommended to use the form of document object instead of Document to reduce the operation of DOM and improve the performance of the program.

Guess you like

Origin blog.csdn.net/liu511623/article/details/129508845