The term “global objects”1 here is not to be confused with the global object2. Here, global objects3 refer to objects in the global scope. The global object4 itself can be accessed by
this in the global scope. In fact, the global scope consists of the properties of the global object5 (including inherited properties, if any).
Honestly, I am completely confused by above words. The first sentence tells me
not to be confused but it does confuse me. Well, English is not my mother language, maybe this is the reason.
There appear 5 times of
global object(s) and 3 times
global object4,5 mean
global objects1 or
Mozilla’s wording is unhelpful. I suggest you ignore it.
There is one global object. This is a well-defined construct within the ECMAScript language specification. It has several purposes, not least of which is that properties of the global object are available everywhere. This is what Mozilla means by “Global Objects”; they’re more accurately and helpfully called “properties of the global object”.
What the article means by global scope is code that is not inside any function. In such code,
window can be thought of as being the global object and is accessible everywhere.
In summary, 2, 4 and 5 are the same thing. 1 and 3 are a poor name for “properties of the global object” that you should forget about.
5 are equivalent to
window variables in your code. This object contains everything that is somehow defined.
If i define a variable
global is a reference to the “global object”.
The Global object is the main object. Think of it as God. Like God, there is only one Global object. Inside the browsers, the
window identifier refers to it.
Global objects are all the objects that are properties of God (the Global object). The browsers have lots of global objects built-in, like
alert method, etc.
You can create additional global objects by:
- declaring global (non-primitive) variables (declaring variables in the global execution context)
- declaring global functions (declaring functions in the global execution context)
It is probably best to refer to global objects as “global variables”, “global functions”, “global members”, “global properties”, etc. so that they are not confused with the Global object.