# 'xxx' is not defined❗️

[JS](../..) ⟩ [error](..) ⟩ [ReferenceError]() ⟩ 'xxx' is not defined

{% hint style="danger" %}
:no\_entry:️ [<mark style="color:red;">**ReferenceError**</mark>]()：[<mark style="color:yellow;">**'xxx' is not defined**</mark>](not-defined):exclamation:
{% endhint %}

{% tabs %}
{% tab title="✨ 範例" %}
* [eval-has-its-own-scope-in-strict-mode](../../concept/env/js-engine/mode/strict-mode/eval-has-its-own-scope-in-strict-mode "mention")
* [accidental-global-variable-in-sloppy-mode](../../concept/env/js-engine/mode/sloppy-mode/accidental-global-variable-in-sloppy-mode "mention")
* [function-in-block-fib](../../val/func/declare/function-in-block-fib "mention"):exclamation:
* [dot-notation-.](../../val/obj/prop/access/dot-notation-. "mention") - when `obj` is [undeclared](../../grammar/token/id/undeclared).
{% endtab %}

{% tab title="⭐️ 重點" %}
{% hint style="warning" %}
with a [function-in-block-fib](../../val/func/declare/function-in-block-fib "mention")

* [sloppy-mode](../../concept/env/js-engine/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](../../concept/env/js-engine/mode/strict-mode "mention"): ⛔ [<mark style="color:red;">**ReferenceError**</mark>](not-defined) (<mark style="color:yellow;">**invisible**</mark> in <mark style="color:orange;">**outer**</mark> [scope](../../scope "mention")):exclamation:
{% endhint %}
{% endtab %}

{% tab title="💈範例" %}
* replit：[modify scope at runtime](https://replit.com/@pegasusroe/modify-scope-at-runtime#index.js)

```javascript
function evalCantModifyScopeInStrictMode() {
    
    'use strict';    // ⭐️ strict mode
    
    // ---------------------------------------------------------------
    // ⭐️ in strict mode, `eval` doesn't introduce new variables into
    //    the surrounding scope, they're local to the script itself.
    eval("var b = 'bbb!';");
    //        ╰── `b` is "local" to the inner script❗
    // ---------------------------------------------------------------
    
    console.log(b);    // `b` is invisible.
    //          ^
    // ⛔ ReferenceError: `b` is not defined
}

evalCantModifyScopeInStrictMode();   // ⛔ ReferenceError (runtime error)
```

* <mark style="color:yellow;">**more examples ...**</mark>
  * [eval-has-its-own-scope-in-strict-mode](../../concept/env/js-engine/mode/strict-mode/eval-has-its-own-scope-in-strict-mode "mention")
  * [accidental-global-variable-in-sloppy-mode](../../concept/env/js-engine/mode/sloppy-mode/accidental-global-variable-in-sloppy-mode "mention")
{% endtab %}

{% tab title="👥 相關" %}
* [](<> "mention") is a [runtime](../runtime "mention").
{% endtab %}
{% endtabs %}
