# global variable

[JS](https://lochiwei.gitbook.io/web/js) ⟩ [scope](https://lochiwei.gitbook.io/web/js/scope) ⟩ [global](https://lochiwei.gitbook.io/web/js/scope/global) ⟩ variable

{% hint style="success" %}
a [var](https://lochiwei.gitbook.io/web/js/variable/declare/var "mention")/ [let](https://lochiwei.gitbook.io/web/js/variable/declare/let "mention") / [const](https://lochiwei.gitbook.io/web/js/variable/declare/const "mention") variable <mark style="color:yellow;">**declared**</mark> in the [](https://lochiwei.gitbook.io/web/js/scope/global "mention").
{% endhint %}

{% tabs %}
{% tab title="⭐️ 重點" %}
{% hint style="warning" %}

* [prop](https://lochiwei.gitbook.io/web/js/scope/global/object/prop "mention") is also exposed as <mark style="color:purple;">**global variable**</mark>.
* <mark style="color:purple;">**global variables**</mark> <mark style="color:red;">**do**</mark>**&#x20;**<mark style="color:yellow;">**get created**</mark> by [declaring variables](https://lochiwei.gitbook.io/web/js/variable/declare) in the [](https://lochiwei.gitbook.io/web/js/scope/global "mention").

👉 [is-global-obj-prop](https://lochiwei.gitbook.io/web/js/variable/declare/var/is-global-obj-prop "mention"):exclamation:
{% endhint %}

{% hint style="info" %}
[variable](https://lochiwei.gitbook.io/web/js/scope/global/variable "mention")s <mark style="color:red;">**don't**</mark>**&#x20;**<mark style="color:yellow;">**get created**</mark> by [declaring variables](https://lochiwei.gitbook.io/web/js/variable/declare) in the [top-level](https://lochiwei.gitbook.io/web/js/scope/top-level "mention") of a module ([module](https://lochiwei.gitbook.io/web/js/scope/module "mention")).
{% endhint %}

{% hint style="warning" %}
[dom-element-with-id](https://lochiwei.gitbook.io/web/js/scope/global/dom-element-with-id "mention") is <mark style="color:red;">**automatically**</mark> <mark style="color:yellow;">**registerd**</mark> as [variable](https://lochiwei.gitbook.io/web/js/scope/global/variable "mention")/[prop](https://lochiwei.gitbook.io/web/js/scope/global/object/prop "mention").
{% endhint %}
{% endtab %}

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

* [accidental-global-variable-in-sloppy-mode](https://lochiwei.gitbook.io/web/js/concept/env/js-engine/mode/sloppy-mode/accidental-global-variable-in-sloppy-mode "mention")
* [var](https://lochiwei.gitbook.io/web/js/scope/global/variable/var "mention")
  * [is-global-obj-prop](https://lochiwei.gitbook.io/web/js/variable/declare/var/is-global-obj-prop "mention"):exclamation:
* [let](https://lochiwei.gitbook.io/web/js/scope/global/variable/let "mention")
  * [shadows-global-object-property](https://lochiwei.gitbook.io/web/js/scope/global/variable/let/shadows-global-object-property "mention"):exclamation:
    {% endtab %}

{% tab title="👥 相關" %}

* [accidental-global-variable-in-sloppy-mode](https://lochiwei.gitbook.io/web/js/concept/env/js-engine/mode/sloppy-mode/accidental-global-variable-in-sloppy-mode "mention")
  {% endtab %}
  {% endtabs %}
