This might be a silly question but I haven't found an answer to it. Why can't we do the following?
window = undefined
OR
document = undefined
I know those are globals and are available in browsers but thinking of how JavaScript works, is it not possible? Are those re-evaluated every time we try to access them?
I am also interested in knowing how the window
or document
objects remain what they are even after setting them to a random value... may be a number
or undefined
or null
.
According to the standard:
Meaning
window
is the context in which all of your scripts are evaluated. If it was writable then the above wouldn't hold and the implementation wouldn't follow the spec, therefore it isn't writable.For similar reasons you can add properties to
document
but you can't override it.You can verify this by looking at the IDL:
window
is the context. You cant't dothis = something
else.document
is property of window. It is not writable or configurable.output