# 'xxx' is not defined❗️

[JS](https://lochiwei.gitbook.io/web/js) ⟩ [error](https://lochiwei.gitbook.io/web/js/err) ⟩ [ReferenceError](https://lochiwei.gitbook.io/web/js/err/ref) ⟩ 'xxx' is not defined

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

{% tabs %}
{% tab title="✨ 範例" %}

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

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

* [sloppy-mode](https://lochiwei.gitbook.io/web/js/concept/env/js-engine/mode/sloppy-mode "mention"): ✅ [<mark style="color:yellow;">**hoisted**</mark>](https://lochiwei.gitbook.io/web/js/scope/hoist/function) / <mark style="color:yellow;">**initialized**</mark> to [undefined](https://lochiwei.gitbook.io/web/js/val/prim/undefined "mention") (in <mark style="color:orange;">**outer**</mark> [scope](https://lochiwei.gitbook.io/web/js/scope "mention"))
* [strict-mode](https://lochiwei.gitbook.io/web/js/concept/env/js-engine/mode/strict-mode "mention"): ⛔ [<mark style="color:red;">**ReferenceError**</mark>](https://lochiwei.gitbook.io/web/js/err/ref/not-defined) (<mark style="color:yellow;">**invisible**</mark> in <mark style="color:orange;">**outer**</mark> [scope](https://lochiwei.gitbook.io/web/js/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](https://lochiwei.gitbook.io/web/js/concept/env/js-engine/mode/strict-mode/eval-has-its-own-scope-in-strict-mode "mention")
  * [accidental-global-variable-in-sloppy-mode](https://lochiwei.gitbook.io/web/js/concept/env/js-engine/mode/sloppy-mode/accidental-global-variable-in-sloppy-mode "mention")
    {% endtab %}

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

* [](https://lochiwei.gitbook.io/web/js/err/ref "mention") is a [runtime](https://lochiwei.gitbook.io/web/js/err/runtime "mention").
  {% endtab %}
  {% endtabs %}
