> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/web/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/web/js/scope/global/object.md).

# global object

🚧 施工中

[JS](/web/js.md) ⟩ [scope](/web/js/scope.md) ⟩ [global](/web/js/scope/global.md) ⟩ object

{% hint style="success" %}
an [object](/web/js/val/obj.md) that <mark style="color:orange;">**always**</mark> exists in the [global scope](/web/js/scope/global.md). \
⭐️ get it with [globalThis](/web/js/scope/global/object/this.md), <mark style="color:orange;">**regardless**</mark> of the <mark style="color:yellow;">**current**</mark> [context](/web/js/concept/context.md)/[environment](/web/js/concept/env.md):exclamation:
{% endhint %}

{% hint style="warning" %} <mark style="color:purple;">**global object**</mark>'s interface <mark style="color:yellow;">**depends**</mark> on the [environment](/web/js/concept/env.md)：

* in [browser](/web/browser.md)： [window](/web/js/scope/global/object/window.md) (a [`Window`](https://developer.mozilla.org/en-US/docs/Web/API/Window) object)
* in [web worker](/web/browser/api/worker.md)： [self](/web/browser/api/worker/self.md) (a [`WorkerGlobalScope`](https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope) object)
* in [Node.js](/web/js/concept/env/node.js.md)：<mark style="color:blue;">`global`</mark> (an object called [`global`](https://nodejs.org/api/globals.html#globals_global))
  {% endhint %}

{% tabs %}
{% tab title="⭐️ 重點" %}
{% hint style="warning" %} <mark style="color:red;">**(read-only)**</mark> [global object property](/web/js/scope/global/object/prop.md):exclamation:

* `NaN`/`Infinity`/ [undefined](/web/js/val/prim/undefined.md) &#x20;
  {% endhint %}

{% hint style="warning" %}
in [global scope](/web/js/scope/global.md),&#x20;

* [var](/web/js/variable/declare/var.md) / [function](/web/js/val/func.md) are <mark style="color:yellow;">**implemented**</mark> as  [global object property](/web/js/scope/global/object/prop.md):exclamation:
* these <mark style="color:yellow;">**properties**</mark> <mark style="color:red;">**cannot**</mark> be <mark style="color:yellow;">**deleted**</mark> with [delete](/web/js/val/obj/prop/create/delete.md):exclamation:

👉 [global var / function is global object property❗️](/web/js/variable/declare/var/is-global-obj-prop.md)
{% endhint %}
{% endtab %}

{% tab title="🔴 主題" %}

* <mark style="color:yellow;">**properties of global object**</mark>
  * <mark style="color:red;">**read-only**</mark>
    * [undefined](/web/js/val/prim/undefined.md)
    * NaN 🚧
    * Infinity 🚧
  * [global object property](/web/js/scope/global/object/prop.md)
    * [accidental global variable in sloppy mode❗️](/web/js/concept/env/js-engine/mode/sloppy-mode/accidental-global-variable-in-sloppy-mode.md)
      {% endtab %}

{% tab title="🧨 雷區" %}
{% hint style="warning" %}
[assignment (=)](/web/js/grammar/op/assign/assignment.md) to an [undeclared identifier](/web/js/grammar/token/id/undeclared.md) will result in [accidental global variable in sloppy mode❗️](/web/js/concept/env/js-engine/mode/sloppy-mode/accidental-global-variable-in-sloppy-mode.md) in [sloppy mode](/web/js/concept/env/js-engine/mode/sloppy-mode.md):exclamation:
{% endhint %}

{% hint style="warning" %}
[global var / function is global object property❗️](/web/js/variable/declare/var/is-global-obj-prop.md)
{% endhint %}

{% hint style="warning" %}
[global let shadows global object property](/web/js/scope/global/variable/let/shadows-global-object-property.md):exclamation:
{% endhint %}
{% endtab %}

{% tab title="🗣 討論" %}

* [What is the 'global' object in NodeJS](https://stackoverflow.com/a/52193294/5409815) ⭐️
* [Is there any difference between a global variable and a property of the Global Object](https://stackoverflow.com/questions/12439256/is-there-any-difference-between-a-global-variable-and-a-property-of-the-global-o)
  {% endtab %}

{% tab title="📗 參考" %}

* [ ] [YDKJS: Scope & Closures (v.2)](/web/master/ref/book/you-dont-know-js-series-v.2/ydkjs-scope-and-closures-v.2.md) >&#x20;
  * [ ] Ch. 3: [The Scope Chain](https://github.com/getify/You-Dont-Know-JS/blob/2nd-ed/scope-closures/ch3.md#chapter-3-the-scope-chain)
  * [ ] Ch. 4: [Around the Global Scope](https://github.com/getify/You-Dont-Know-JS/blob/2nd-ed/scope-closures/ch4.md#chapter-4-around-the-global-scope)
    {% endtab %}

{% tab title="📘 手冊" %}

* [ ] [Global object](https://developer.mozilla.org/en-US/docs/Glossary/Global_object)
* [ ] [global context](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this#global_context)
* [ ] [globalThis](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis)
  {% endtab %}

{% tab title="🚧" %}

* [ ] NaN
* [ ] Infinity
* [ ] global
* [x] function declarations
  {% endtab %}
  {% endtabs %}
