Skip to content

Commit c2fc52e

Browse files
authored
More content to Global object glossary (#34471)
1 parent ebaebbb commit c2fc52e

File tree

1 file changed

+10
-3
lines changed
  • files/en-us/glossary/global_object

1 file changed

+10
-3
lines changed

files/en-us/glossary/global_object/index.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@ page-type: glossary-definition
66

77
{{GlossarySidebar}}
88

9-
A global object is an {{glossary("object")}} that always exists in the {{glossary("global scope")}}.
9+
The **global object** in JavaScript is an {{glossary("object")}} which represents the {{glossary("global scope")}}.
1010

11-
In JavaScript, there's always a global object defined. In a web browser, when scripts create global variables defined with the [`var`](/en-US/docs/Web/JavaScript/Reference/Statements/var) keyword, they're created as members of the global object. (In {{Glossary("Node.js")}} this is not the case.) The global object's {{Glossary("interface")}} depends on the execution context in which the script is running. For example:
11+
> **Note:** _Globally available objects_, which are objects in the {{glossary("global scope")}}, are sometimes also referred to as global objects, but strictly speaking, there is only one global object per environment.
12+
13+
In each JavaScript environment, there's always a global object defined. The global object's {{Glossary("interface")}} depends on the execution context in which the script is running. For example:
1214

1315
- In a web browser, any code which the script doesn't specifically start up as a background task has a {{domxref("Window")}} as its global object. This is the vast majority of JavaScript code on the Web.
1416
- Code running in a {{domxref("Worker")}} has a {{domxref("WorkerGlobalScope")}} object as its global object.
1517
- Scripts running under {{Glossary("Node.js")}} have an object called [`global`](https://nodejs.org/api/globals.html#globals_global) as their global object.
1618

1719
The [`globalThis`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis) global property allows one to access the global object regardless of the current environment.
1820

19-
[`var`](/en-US/docs/Web/JavaScript/Reference/Statements/var) statements and [function declarations](/en-US/docs/Web/JavaScript/Reference/Statements/function) at the top level create properties of the global object. On the other hand, {{jsxref("Statements/let", "let")}} and {{jsxref("Statements/const", "const")}} declarations never create properties of the global object.
21+
[`var`](/en-US/docs/Web/JavaScript/Reference/Statements/var) statements and [function declarations](/en-US/docs/Web/JavaScript/Reference/Statements/function) at the top level of a script create properties of the global object. On the other hand, {{jsxref("Statements/let", "let")}} and {{jsxref("Statements/const", "const")}} declarations never create properties of the global object.
2022

2123
The properties of the global object are automatically added to the {{glossary("global scope")}}.
2224

@@ -37,6 +39,11 @@ console.log(global === global.global); // true (in Node.js)
3739
- {{glossary("global scope")}}
3840
- {{glossary("object")}}
3941

42+
- {{jsxref("globalThis")}}
4043
- {{domxref("Window")}}
4144
- {{domxref("WorkerGlobalScope")}}
45+
- {{domxref("Window.window")}}
46+
- {{domxref("Window.self")}}
47+
- {{domxref("Window.frames")}}
48+
- {{domxref("WorkerGlobalScope.self")}}
4249
- [`global`](https://nodejs.org/api/globals.html#globals_global)

0 commit comments

Comments
 (0)