---
description: 🚧 施工中
---

# global object

[JS](../..) ⟩ [scope](..) ⟩ [global]() ⟩ object

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

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

* in [browser](../../../browser "mention")： [window](object/window "mention") (a [`Window`](https://developer.mozilla.org/en-US/docs/Web/API/Window) object)
* in [worker](../../../browser/api/worker "mention")： [self](../../../browser/api/worker/self "mention") (a [`WorkerGlobalScope`](https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope) object)
* in [node.js](../../concept/env/node.js "mention")：<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> [prop](object/prop "mention"):exclamation:

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

{% hint style="warning" %}
in [](<> "mention"),&#x20;

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

👉 [is-global-obj-prop](../../variable/declare/var/is-global-obj-prop "mention")
{% endhint %}
{% endtab %}

{% tab title="🔴 主題" %}
* <mark style="color:yellow;">**properties of global object**</mark>
  * <mark style="color:red;">**read-only**</mark>
    * [undefined](../../val/prim/undefined "mention")
    * NaN 🚧
    * Infinity 🚧
  * [prop](object/prop "mention")
    * [accidental-global-variable-in-sloppy-mode](../../concept/env/js-engine/mode/sloppy-mode/accidental-global-variable-in-sloppy-mode "mention")
{% endtab %}

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

{% hint style="warning" %}
[is-global-obj-prop](../../variable/declare/var/is-global-obj-prop "mention")
{% endhint %}

{% hint style="warning" %}
[shadows-global-object-property](variable/let/shadows-global-object-property "mention"):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-and-closures-v.2](../../../master/ref/book/you-dont-know-js-series-v.2/ydkjs-scope-and-closures-v.2 "mention") >&#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 %}
