What is document in JavaScript and what is its scope?

后端 未结 1 1873
南方客
南方客 2021-01-24 00:04
var document = \"temp\";

function showDocument()
{
    alert(document); // temp or HTML DOM Document
}

It showed \"HTML DOM Document\" for me, which s

相关标签:
1条回答
  • 2021-01-24 00:45

    It's a read-only property of the global (window) object. Its value is a native object representing the current HTML/XML/whatever document loaded into the window.

    To modify the DOM, use DOM manipulation APIs.

    edit — to clarify, the "document" property of the window object (or, if you prefer, the global variable called "document") is itself immutable, and its value cannot be changed by JavaScript. The value, however, is a reference to an object, an object that is mutable in all sorts of ways.

    0 讨论(0)
提交回复
热议问题