# var redeclaration applied even in strict mode❗️

* [JS](https://lochiwei.gitbook.io/web/js) ⟩ [variable](https://lochiwei.gitbook.io/web/js/variable) ⟩ [var](https://lochiwei.gitbook.io/web/js/variable/declare/var) ⟩ redeclaration applied
* [JS](https://lochiwei.gitbook.io/web/js) ⟩ [grammar](https://lochiwei.gitbook.io/web/js/grammar) ⟩ [declaration](https://lochiwei.gitbook.io/web/js/grammar/declare) ⟩ [redeclaration](https://lochiwei.gitbook.io/web/js/grammar/declare/redeclare) ⟩ var redeclaration applied

{% hint style="warning" %}
[](https://lochiwei.gitbook.io/web/js/variable/declare/var "mention") <mark style="color:purple;">**redeclaration**</mark>&#x20;

* the <mark style="color:yellow;">**declaration**</mark> part is <mark style="color:yellow;">**ignored**</mark> :exclamation:
* ⭐️ the [assignment](https://lochiwei.gitbook.io/web/js/grammar/op/assign/assignment "mention") part is <mark style="color:red;">**applied**</mark>:exclamation:
* <mark style="color:red;">**won't**</mark>**&#x20;**<mark style="color:yellow;">**trigger**</mark> any [err](https://lochiwei.gitbook.io/web/js/err "mention") ( <mark style="color:red;">**even in**</mark> [strict-mode](https://lochiwei.gitbook.io/web/js/concept/env/js-engine/mode/strict-mode "mention"):exclamation:)
  {% endhint %}

{% tabs %}
{% tab title="⭐️ 重點" %}
{% hint style="warning" %}
JS is <mark style="color:green;">**lenient**</mark> with [](https://lochiwei.gitbook.io/web/js/variable/declare/var "mention"), <mark style="color:red;">**strict**</mark> with [let](https://lochiwei.gitbook.io/web/js/variable/declare/let "mention").

* [redeclare](https://lochiwei.gitbook.io/web/js/variable/declare/var/redeclare "mention")
* [no-redeclare](https://lochiwei.gitbook.io/web/js/variable/declare/let/no-redeclare "mention")
  {% endhint %}
  {% endtab %}

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

* :white\_check\_mark:[no-redeclare](https://lochiwei.gitbook.io/web/js/variable/declare/let/no-redeclare "mention")
  {% endtab %}

{% tab title="💈範例" %}

* replit：[var redeclaration](https://replit.com/@pegasusroe/var-redeclaration#index.js)

```javascript
function f() {
    
    var a = 123;        // var declaration
    
    var a = 'hello';    // ⭐️ var redeclaration 
                        //    • "declaration": ignored.
                        //    • "assignment" : applied❗
    
    log(a);             // 'hello'
}
```

{% endtab %}

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

* [ ] [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)
  {% endtab %}
  {% endtabs %}
