---
description: 🚧 under construction
---

# var is a statement❗️

[JS](../../..) ⟩ [variable](../..) ⟩ [var]() ⟩ var is statement:exclamation:

{% hint style="warning" %}
(<mark style="color:red;">**side effects**</mark>)

[](<> "mention") is a [statement](../../../grammar/statement "mention"), <mark style="color:yellow;">**instead of**</mark> a [declare](../../../grammar/declare "mention")：

* it <mark style="color:red;">**doesn't**</mark>**&#x20;**<mark style="color:yellow;">**follow**</mark> normal [lexical scoping](../../../scope/lexical-scope) <mark style="color:yellow;">**rules**</mark>.&#x20;
* may <mark style="color:yellow;">**create**</mark>**&#x20;**<mark style="color:red;">**side effects**</mark>：
  * [is-global-obj-prop](is-global-obj-prop "mention")
  * [redeclare](redeclare "mention")
  * [in-block-cant-shadow](in-block-cant-shadow "mention")
{% endhint %}

{% tabs %}
{% tab title="⭐️ 重點" %}
{% hint style="success" %}
📘 [js-spec](../../../../master/ref/js-spec "mention") ⟩ [Variable Statement](https://tc39.es/ecma262/#sec-variable-statement)

* <mark style="color:purple;">**var**</mark> [statement](../../../grammar/statement "mention") <mark style="color:yellow;">**declares**</mark> [..](../.. "mention")(s) that are <mark style="color:yellow;">**scoped**</mark> to the [running execution context](https://tc39.es/ecma262/#running-execution-context)'s <mark style="color:orange;">**VariableEnvironment**</mark>.&#x20;
* <mark style="color:purple;">**var**</mark> [..](../.. "mention")(s) are <mark style="color:yellow;">**created**</mark> when their containing [Environment Record](https://tc39.es/ecma262/#sec-environment-records) is <mark style="color:yellow;">**instantiated**</mark> and are <mark style="color:yellow;">**initialized**</mark> to [undefined](../../../val/prim/undefined "mention") when created.&#x20;
* Within the [scope](../../../scope "mention") of any <mark style="color:orange;">**VariableEnvironment**</mark> a <mark style="color:yellow;">**common**</mark> [BindingIdentifier](https://tc39.es/ecma262/#prod-BindingIdentifier) may appear in <mark style="color:red;">**more than one**</mark> [VariableDeclaration](https://tc39.es/ecma262/#prod-VariableDeclaration) but those <mark style="color:yellow;">**declarations**</mark> collectively define <mark style="color:red;">**only one**</mark> [..](../.. "mention").&#x20;
* A [..](../.. "mention") defined by a [VariableDeclaration](https://tc39.es/ecma262/#prod-VariableDeclaration) with an [Initializer](https://tc39.es/ecma262/#prod-Initializer) is <mark style="color:yellow;">**assigned**</mark> the <mark style="color:yellow;">**value**</mark> of its [Initializer](https://tc39.es/ecma262/#prod-Initializer)'s [AssignmentExpression](https://tc39.es/ecma262/#prod-AssignmentExpression) when the [VariableDeclaration](https://tc39.es/ecma262/#prod-VariableDeclaration) is <mark style="color:yellow;">**executed**</mark>, <mark style="color:red;">**not**</mark> <mark style="color:yellow;">**when**</mark> the variable is <mark style="color:yellow;">**created**</mark>.
{% endhint %}
{% endtab %}

{% tab title="👥 相關" %}
* :white\_check\_mark:[stop-using-var](stop-using-var "mention")
* :no\_entry:[statement-expected](../../../grammar/statement/statement-expected "mention"):exclamation:
{% endtab %}

{% tab title="📘 手冊" %}
* [ ] 📘 [js-spec](../../../../master/ref/js-spec "mention") ⟩ [Variable Statement](https://tc39.es/ecma262/#sec-variable-statement) ⭐️
* [ ] [Statements and declarations](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements) ⟩ [declaring variables](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements#declaring_variables) ⟩ [var](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var)
* [ ] [Difference between statements and declarations](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements#difference_between_statements_and_declarations) ⭐️⭐️⭐️ ❗️❗️❗️
{% endtab %}

{% tab title="🚧" %}
* [ ] VariableEnvironment
* [ ] Environment Record
{% endtab %}
{% endtabs %}
