0

Where are global variables really stored? I know this question exists, but I am currently reading a book that says that global variables are stored as attributes of the global execution context object.

But the link I included in the first paragraph says that they are properties of the Window object. So what is the relationship between the Window and the Global Execution Context object, if any? If none, is the book I'm reading wrong?

3
  • Both can be correct. I think the global execution context refers to the implementation, it doesn't necessarily mean the window object. The window object is the global object in browsers. Commented Jan 19, 2015 at 3:43
  • "many host environments will put a property in the global object whose value is a reference to the global object itself", so it doesn't necessarily be called window but still refers to the global object Commented Jan 19, 2015 at 3:44
  • 1
    There is no "Global Execution Context object", there is a global object and a global execution context though. ;-) Commented Jan 19, 2015 at 3:47

1 Answer 1

2

Where are global variables really stored?

Global variables are made properties of a lexical environment in a global execution context, the same as function variables are made properties of a function lexical environment.

For convenience, they are also made properties of the global object.

I am currently reading a book that says that global variables are stored as attributes of the global execution context object.

More or less. Terminology was changed for ES5, previously there was a concept of a variable object to store variables within an execution context, but it was only a specification device and not an actual object that could be accessed.

ES5 references a lexical environment, which includes a variable environment, see EMCA-262 §10.3

But the link I included in the first paragraph says that they are properties of the Window object.

Within a browser, the window object is effectively an alias of the global object. window is a host object, so it can have more properties and methods than the built–in global object.

So what is the relationship between the Window and the Global Execution Context object, if any?

I think that's explained above. In short, in a browser, the global and window objects are effectively (but not exactly) the same thing.

If none, is the book I'm reading wrong?

No, but it seems to have confused you. ;-)

See also: MDN: Window.window

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.