HeavensGate666
HeavensGate666

Reputation: 75

Global Object is a Global Variable?

MDN Says:

A global variable, window, representing the window in which the script is running, is exposed to JavaScript

this is very confusing because window is a global variable. How is window a global variable and a global object?

Upvotes: 0

Views: 76

Answers (2)

HeavensGate666
HeavensGate666

Reputation: 75

"A global object is an object that always exists in the global scope.

In JavaScript, there's always a global object defined. In a web browser, when scripts create global variables, they're created as members of the global object. (In Node.js this is not the case.) The global object's interface depends on the execution context in which the script is running. For example:

In a web browser, any code which the script doesn't specifically start up as a background task has a Window as its global object. This is the vast majority of JavaScript code on the Web. Code running in a Worker has a WorkerGlobalScope object as its global object. Scripts running under Node.js have an object called global as their global object." - MDN ( https://developer.mozilla.org/en-US/docs/Glossary/Global_object )

"A global variable is a variable that is declared in the global scope in other words, a variable that is visible from all other scopes.

In JavaScript it is a property of the global object." - MDN ( https://developer.mozilla.org/en-US/docs/Glossary/Global_variable )

Upvotes: 0

wojonatior
wojonatior

Reputation: 66

Object would be the type of window.

So window is a global variable that is an object.

Upvotes: 1

Related Questions