---
description: 🚧 施工中
---

# strict mode

[JS](../../../..) ⟩ [concepts](../../../../../browser/concepts) ⟩ [environment](../..) ⟩ [JS engine](..) ⟩ [mode]() ⟩ strict

{% hint style="warning" %}
:shield: <mark style="color:red;">**always**</mark>**&#x20;**<mark style="color:yellow;">**use**</mark> [strict-mode](strict-mode "mention"):exclamation: (:point\_right: see [why](strict-mode/always))
{% 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](sloppy-mode "mention")".
{% endhint %}

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

* [duplicate-parameter](../../../../err/syntax/duplicate-parameter "mention"):exclamation:
* [function-in-block-fib](../../../../val/func/declare/function-in-block-fib "mention") is <mark style="color:yellow;">**local**</mark> to the [block](../../../../grammar/statement/other/block "mention").
{% endhint %}

{% hint style="warning" %}
JS is <mark style="color:green;">**lenient**</mark> with [var](../../../../variable/declare/var "mention"), <mark style="color:red;">**strict**</mark> with [let](../../../../variable/declare/let "mention").

* [redeclare](../../../../variable/declare/var/redeclare "mention"), even in [strict-mode](strict-mode "mention"):exclamation:
* [no-redeclare](../../../../variable/declare/let/no-redeclare "mention"), even in [sloppy-mode](sloppy-mode "mention"):exclamation:
{% endhint %}

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

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

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

{% tab title="🔴 主題" %}
* :white\_check\_mark:[always](strict-mode/always "mention")
* [eval-has-its-own-scope-in-strict-mode](strict-mode/eval-has-its-own-scope-in-strict-mode "mention")
* [redeclare](../../../../variable/declare/var/redeclare "mention") (<mark style="color:yellow;">**even in**</mark>**&#x20;**<mark style="color:purple;">**strict mode**</mark>):exclamation:
* [duplicate-parameter](../../../../err/syntax/duplicate-parameter "mention") (<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](../../../../err/syntax/delete-of-an-unqualified-identifier-in-strict-mode "mention")
* :no\_entry:[octal-literals-not-allowed-in-strict-mode](../../../../err/syntax/octal-literals-not-allowed-in-strict-mode "mention")
{% 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 %}
