> 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/module.md).

# module scope

🚧 施工中

[JS](/web/js.md) ⟩ [concepts](/web/browser/concepts.md) ⟩ [scope](/web/js/scope.md) ⟩ module

{% hint style="success" %}
[scope](/web/js/scope.md) for code running <mark style="color:yellow;">**in**</mark> [module](/web/js/module.md) <mark style="color:yellow;">**mode**</mark>.
{% endhint %}

{% tabs %}
{% tab title="⭐️ 重點" %}
{% hint style="warning" %}
in a [module](/web/js/module.md) there's <mark style="color:red;">**no**</mark> "<mark style="color:purple;">**module-wide scope**</mark>**&#x20;**<mark style="color:yellow;">**object**</mark>" for these <mark style="color:yellow;">**top-level**</mark> [declaration](/web/js/grammar/declare.md)s to be added to as [property](/web/js/val/obj/prop.md).

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

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

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

* [module](/web/js/module.md)
  {% endtab %}

{% tab title="🗺️ 圖表" %}

<div><figure><img src="https://ringojs.org/documentation/images/modulescope.png" alt=""><figcaption><p>✅ each module has its own scope </p></figcaption></figure> <figure><img src="https://ringojs.org/documentation/images/scriptscope.png" alt=""><figcaption><p>❌ global object shared by all scripts</p></figcaption></figure></div>
{% endtab %}

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

* [ ] ringojs ⟩ [Understanding module and global scope](https://ringojs.org/documentation/module_and_global_scope/) ⭐️
* [ ] [YDKJS: Scope & Closures (v.2)](/web/master/ref/book/you-dont-know-js-series-v.2/ydkjs-scope-and-closures-v.2.md) ⟩ Ch. 4 ⟩ [ES Modules](https://github.com/getify/You-Dont-Know-JS/blob/2nd-ed/scope-closures/ch4.md#es-modules-esm)
  {% endtab %}

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

* [ ] [Scope](https://developer.mozilla.org/en-US/docs/Glossary/Scope)
  {% endtab %}
  {% endtabs %}
