# let redeclaration not allowed even in sloppy mode❗️

[JS](https://lochiwei.gitbook.io/web/js) ⟩ [declaration](https://lochiwei.gitbook.io/web/js/grammar/declare) ⟩ [variable](https://lochiwei.gitbook.io/web/js/variable/declare) ⟩ [let](https://lochiwei.gitbook.io/web/js/variable/declare/let) ⟩ redeclaration not allowed

{% hint style="danger" %}
[](https://lochiwei.gitbook.io/web/js/variable/declare/let "mention") <mark style="color:red;">**doesn't**</mark>**&#x20;**<mark style="color:yellow;">**allow**</mark> [<mark style="color:red;">**redeclarations**</mark>](https://lochiwei.gitbook.io/web/js/variable/redeclare/let) (<mark style="color:yellow;">**even**</mark> in [sloppy-mode](https://lochiwei.gitbook.io/web/js/concept/env/js-engine/mode/sloppy-mode "mention")):exclamation:
{% endhint %}

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

* [redeclare](https://lochiwei.gitbook.io/web/js/variable/declare/var/redeclare "mention"), even in [strict-mode](https://lochiwei.gitbook.io/web/js/concept/env/js-engine/mode/strict-mode "mention"):exclamation:
* [no-redeclare](https://lochiwei.gitbook.io/web/js/variable/declare/let/no-redeclare "mention"), even in [sloppy-mode](https://lochiwei.gitbook.io/web/js/concept/env/js-engine/mode/sloppy-mode "mention"):exclamation:
  {% endhint %}
  {% endtab %}

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

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

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

* replit：[let doesn't allow redeclarations](https://replit.com/@pegasusroe/let-doesnt-allow-redeclaration#index.js)
* 👉 [syntax](https://lochiwei.gitbook.io/web/js/err/syntax "mention") ⟩ [redeclare](https://lochiwei.gitbook.io/web/js/err/syntax/redeclare "mention")

```javascript
// ❌ function -> let ?
function f() { }
let f = 123;
//  ^
// ⛔ SyntaxError: Identifier 'f' has already been declared

// ❌ let -> let ?
let male = true;
let male = false;
//  ^^^^
// ⛔ SyntaxError: Identifier 'male' has already been declared

// ❌ var -> let ?
var name = 'Joe';
let name = 'Suzy';
//  ^^^^
// ⛔ SyntaxError: Identifier 'name' has already been declared

// ❌ let -> var ?
let age = 50;
var age = 25;
//  ^^^
// ⛔ SyntaxError: Identifier 'age' has already been declared

// ⭐️ block scope
{
    let x = 10;
    var x = 20;    // ❗ 這怪啦？ "var" 不是沒有 "block scope" 嗎？
    //  ^
    // ⛔ SyntaxError: Identifier 'x' has already been declared
}
```

{% endtab %}

{% tab title="📗 參考" %}

* [ ] [ydkjs-scope-and-closures-v.2](https://lochiwei.gitbook.io/web/master/ref/book/you-dont-know-js-series-v.2/ydkjs-scope-and-closures-v.2 "mention") ⟩ Ch. 3: [The Scope Chain](https://github.com/getify/You-Dont-Know-JS/blob/2nd-ed/scope-closures/ch3.md#chapter-3-the-scope-chain)
  {% endtab %}

{% tab title="🚧" %}

* [ ] redeclaration
  {% endtab %}
  {% endtabs %}
