> 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/concept/env/js-engine/mode/strict-mode.md).

# strict mode

🚧 施工中

[JS](/web/js.md) ⟩ [concepts](/web/browser/concepts.md) ⟩ [environment](/web/js/concept/env.md) ⟩ [JS engine](/web/js/concept/env/js-engine.md) ⟩ [mode](/web/js/concept/env/js-engine/mode.md) ⟩ strict

{% hint style="warning" %}
:shield: <mark style="color:red;">**always**</mark>**&#x20;**<mark style="color:yellow;">**use**</mark> [strict mode](/web/js/concept/env/js-engine/mode/strict-mode.md):exclamation: (:point\_right: see [why](/web/js/concept/env/js-engine/mode/strict-mode/always.md))
{% endhint %}

{% hint style="success" %}
a way to *opt in* to a <mark style="color:yellow;">**restricted variant**</mark> of JavaScript, thereby implicitly opting-out of "[sloppy mode](/web/js/concept/env/js-engine/mode/sloppy-mode.md)".
{% endhint %}

{% tabs %}
{% tab title="⭐️ 重點" %}
{% hint style="danger" %} <mark style="color:red;">**in**</mark> <mark style="color:purple;">**strict mode**</mark>：

* [duplicate parameter not allowed in strict mode❗️](/web/js/err/syntax/duplicate-parameter.md):exclamation:
* [function in block (FiB)](/web/js/val/func/declare/function-in-block-fib.md) is <mark style="color:yellow;">**local**</mark> to the [block](/web/js/grammar/statement/other/block.md).
  {% endhint %}

{% 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 %}

{% hint style="warning" %} <mark style="color:yellow;">**referencing**</mark> a [function in block (FiB)](/web/js/val/func/declare/function-in-block-fib.md) <mark style="color:yellow;">**outside**</mark> the <mark style="color:yellow;">**block**</mark>：

* [sloppy mode](/web/js/concept/env/js-engine/mode/sloppy-mode.md): \
  ✅ [<mark style="color:yellow;">**hoisted**</mark>](/web/js/scope/hoist/function.md) / <mark style="color:yellow;">**initialized**</mark> to [undefined](/web/js/val/prim/undefined.md) (in <mark style="color:orange;">**outer**</mark> [scope](/web/js/scope.md))
* [strict mode](/web/js/concept/env/js-engine/mode/strict-mode.md): \
  ⛔ [<mark style="color:red;">**ReferenceError**</mark>](/web/js/err/ref/not-defined.md) (<mark style="color:yellow;">**invisible**</mark> in <mark style="color:orange;">**outer**</mark> [scope](/web/js/scope.md)):exclamation:
  {% endhint %}

{% hint style="warning" %}
[class](/web/js/val/class.md) <mark style="color:yellow;">**/**</mark> [ES module](/web/js/module/es.md) <mark style="color:red;">**always**</mark> works in [strict mode](/web/js/concept/env/js-engine/mode/strict-mode.md)❗️
{% endhint %}
{% endtab %}

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

* :white\_check\_mark:[always use strict mode](/web/js/concept/env/js-engine/mode/strict-mode/always.md)
* [eval has its own scope in strict mode](/web/js/concept/env/js-engine/mode/strict-mode/eval-has-its-own-scope-in-strict-mode.md)
* [var redeclaration applied even in strict mode❗️](/web/js/variable/declare/var/redeclare.md) (<mark style="color:yellow;">**even in**</mark>**&#x20;**<mark style="color:purple;">**strict mode**</mark>):exclamation:
* [duplicate parameter not allowed in strict mode❗️](/web/js/err/syntax/duplicate-parameter.md) (<mark style="color:yellow;">**in**</mark>**&#x20;**<mark style="color:purple;">**strict mode**</mark>):exclamation:
  {% endtab %}

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

* :no\_entry:[delete of an unqualified identifier in strict mode❗️](/web/js/err/syntax/delete-of-an-unqualified-identifier-in-strict-mode.md)
* :no\_entry:[octal literals not allowed in strict mode❗️](/web/js/err/syntax/octal-literals-not-allowed-in-strict-mode.md)
  {% endtab %}

{% tab title="🖥️ 影片" %}
{% embed url="<https://youtu.be/G9QTBS2x8U4>" %}
{% endtab %}

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

* [ ] &#x20;[`eval` of strict mode code does not introduce new variables into the surrounding scope](https://whereswalden.com/2011/01/10/new-es5-strict-mode-support-new-vars-created-by-strict-mode-eval-code-are-local-to-that-code-only/)
* [ ] itHome ⟩ [你不可不知的 JavaScript 二三事](https://ithelp.ithome.com.tw/users/20112483/ironman/2016) ⟩&#x20;
  * [ ] [#Day11：Strict Mode (嚴謹模式)](https://ithelp.ithome.com.tw/articles/10205274)
  * [ ] [#Day12：看 Strict Mode 如何施展「還我漂亮拳」(1)](https://ithelp.ithome.com.tw/articles/10205275)
  * [ ] [#Day13：看 Strict Mode 如何施展「還我漂亮拳」(2)](https://ithelp.ithome.com.tw/articles/10205334)
    {% endtab %}

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

* [Strict mode](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode)
  {% endtab %}
  {% endtabs %}
