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

# variable hoisting

[JS](../..) ⟩ [scope](..) ⟩ [hoisting]() ⟩ variable hoisting

{% hint style="success" %}
* [var](variable/var "mention")
  * [id](../../grammar/token/id "mention")： <mark style="color:yellow;">**hoisted**</mark> to the <mark style="color:yellow;">**top**</mark> of its enclosing [function](../function "mention").\
    ( 👉 [in-block-cant-shadow](../../variable/declare/var/in-block-cant-shadow "mention"):exclamation:)
  * [val](../../val "mention")： <mark style="color:yellow;">**initialized**</mark> to [undefined](../../val/prim/undefined "mention"):exclamation:
* [let-const](variable/let-const "mention")
  * [id](../../grammar/token/id "mention")： <mark style="color:yellow;">**hoisted**</mark> to the <mark style="color:yellow;">**top**</mark> of its [..](.. "mention").
  * [val](../../val "mention")： <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>](../../err/ref/cannot-access-before-init))
{% endhint %}

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

{% tab title="🔴 主題" %}
* [var](variable/var "mention")
* [let-const](variable/let-const "mention")
* <mark style="color:yellow;">**related topics**</mark>
  * [declare](../../variable/declare "mention")
{% endtab %}

{% tab title="👥 相關" %}
* compare： [function](function "mention")
{% 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. 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 %}
