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

# variable hoisting

🚧 施工中

[JS](/web/js.md) ⟩ [scope](/web/js/scope.md) ⟩ [hoisting](/web/js/scope/hoist.md) ⟩ variable hoisting

{% hint style="success" %}

* [var hoisting](/web/js/scope/hoist/variable/var.md)
  * [identifier](/web/js/grammar/token/id.md)： <mark style="color:yellow;">**hoisted**</mark> to the <mark style="color:yellow;">**top**</mark> of its enclosing [function scope](/web/js/scope/function.md).\
    ( 👉 [var has no block scope❗️](/web/js/variable/declare/var/in-block-cant-shadow.md):exclamation:)
  * [value](/web/js/val.md)： <mark style="color:yellow;">**initialized**</mark> to [undefined](/web/js/val/prim/undefined.md):exclamation:
* [let/const/class hoisting](/web/js/scope/hoist/variable/let-const.md)
  * [identifier](/web/js/grammar/token/id.md)： <mark style="color:yellow;">**hoisted**</mark> to the <mark style="color:yellow;">**top**</mark> of its [scope](/web/js/scope.md).
  * [value](/web/js/val.md)： <mark style="color:red;">**uninitialized**</mark>:exclamation:(<mark style="color:yellow;">**referencing**</mark> it <mark style="color:red;">**before init**</mark> causes [<mark style="color:red;">**ReferenceError**</mark>](/web/js/err/ref/cannot-access-before-init.md))
    {% endhint %}

{% tabs %}
{% tab title="⭐️ 重點" %}
{% hint style="warning" %}
in the same [scope](/web/js/scope.md), [function hoisting](/web/js/scope/hoist/function.md) has <mark style="color:yellow;">**higher priority**</mark> over [variable hoisting](/web/js/scope/hoist/variable.md). ( :point\_right: [function hoisting first❗️](/web/js/scope/hoist/function/first.md):exclamation:)
{% endhint %}
{% endtab %}

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

* [var hoisting](/web/js/scope/hoist/variable/var.md)
* [let/const/class hoisting](/web/js/scope/hoist/variable/let-const.md)
* <mark style="color:yellow;">**related topics**</mark>
  * [variable declaration](/web/js/variable/declare.md)
    {% endtab %}

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

* compare： [function hoisting](/web/js/scope/hoist/function.md)
  {% 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. 1](https://github.com/getify/You-Dont-Know-JS/blob/2nd-ed/scope-closures/ch1.md#chapter-1-whats-the-scope) ⟩ [Hoisting](https://github.com/getify/You-Dont-Know-JS/blob/2nd-ed/scope-closures/ch1.md#hoisting)
  * [ ] Ch. 5 ⟩ [Hoisting: Declaration vs. Expression](https://github.com/getify/You-Dont-Know-JS/blob/2nd-ed/scope-closures/ch5.md#hoisting-declaration-vs-expression)
  *

{% endtab %}
{% endtabs %}
