> 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/let/no-redeclare.md).

# let redeclaration not allowed even in sloppy mode❗️

🚧 under construction

[JS](/web/js.md) ⟩ [declaration](/web/js/grammar/declare.md) ⟩ [variable](/web/js/variable/declare.md) ⟩ [let](/web/js/variable/declare/let.md) ⟩ redeclaration not allowed

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

{% tabs %}
{% tab title="⭐️ 重點" %}
{% hint style="warning" %}
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 %}
  {% endtab %}

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

* :beginner:[let redeclaration](/web/js/variable/redeclare/let.md)
* :exclamation:[var redeclaration applied even in strict mode❗️](/web/js/variable/declare/var/redeclare.md)
  {% endtab %}

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

* replit：[let doesn't allow redeclarations](https://replit.com/@pegasusroe/let-doesnt-allow-redeclaration#index.js)
* 👉 [⛔️ SyntaxError](/web/js/err/syntax.md) ⟩ [identifier 'xxx' has already been declared❗️](/web/js/err/syntax/redeclare.md)

```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 & Closures (v.2)](/web/master/ref/book/you-dont-know-js-series-v.2/ydkjs-scope-and-closures-v.2.md) ⟩ 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 %}
