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

# variable declaration

* [JS](/web/js.md) ⟩ [declaration](/web/js/grammar/declare.md) ⟩ variable
* [JS](/web/js.md) ⟩ [variable](/web/js/variable.md) ⟩ declaration

{% hint style="success" %}
([declaration](/web/js/grammar/declare.md)) declares a [var](/web/js/variable/declare/var.md) / [let](/web/js/variable/declare/let.md) / [const](/web/js/variable/declare/const.md) variable.
{% endhint %}

{% tabs %}
{% tab title="⭐️ 重點" %}
{% hint style="warning" %}
[function](/web/js/val/func.md) ([declaration](/web/js/val/func/declare.md)) <mark style="color:yellow;">**vs.**</mark> <mark style="color:purple;">**variable declarations**</mark>

* [function declaration](/web/js/val/func/declare.md) is <mark style="color:red;">**instantly**</mark>**&#x20;**<mark style="color:yellow;">**fully**</mark>**&#x20;**<mark style="color:red;">**initialized**</mark>.
* <mark style="color:purple;">**variable declarations**</mark> is [undefined](/web/js/val/prim/undefined.md)/<mark style="color:red;">**uninitialized**</mark> <mark style="color:yellow;">**initially**</mark>.&#x20;

:point\_right: [hoisting](/web/js/scope/hoist.md)

📗 JS.info ⟩ [Function Declarations](https://javascript.info/closure#step-2-function-declarations)
{% endhint %}

{% hint style="warning" %}
(:exclamation:[redeclaration](/web/js/grammar/declare/redeclare.md) ) JS is <mark style="color:green;">**lenient**</mark> with [var](/web/js/variable/declare/var.md), <mark style="color:red;">**strict**</mark> with [let](/web/js/variable/declare/let.md).

* [var redeclaration applied even in strict mode❗️](/web/js/variable/declare/var/redeclare.md), even in [strict mode](/web/js/concept/env/js-engine/mode/strict-mode.md):exclamation:
* [let redeclaration not allowed even in sloppy mode❗️](/web/js/variable/declare/let/no-redeclare.md), even in [sloppy mode](/web/js/concept/env/js-engine/mode/sloppy-mode.md):exclamation:
  {% endhint %}

{% hint style="warning" %}
there is <mark style="color:red;">**no**</mark> [type](/web/js/val/type.md) <mark style="color:yellow;">**associated**</mark> with <mark style="color:purple;">**variable declarations**</mark>:exclamation:
{% endhint %}
{% endtab %}

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

* <mark style="color:yellow;">**variable declarations**</mark>
  * [var](/web/js/variable/declare/var.md) / [let](/web/js/variable/declare/let.md) / [const](/web/js/variable/declare/const.md)
  * [initial value](/web/js/variable/declare/initial-value.md)
  * [redeclaration](/web/js/grammar/declare/redeclare.md)
    {% endtab %}

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

* [function declaration](/web/js/val/func/declare.md)
* [hoisting](/web/js/scope/hoist.md) / [var hoisting](/web/js/scope/hoist/variable/var.md)
  {% endtab %}

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

* [ ] [Grammar and types](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types) ⟩ [variable declarations](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#declarations)
  {% endtab %}
  {% endtabs %}
