> 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/err/ref/not-defined.md).

# 'xxx' is not defined❗️

[JS](/web/js.md) ⟩ [error](/web/js/err.md) ⟩ [ReferenceError](/web/js/err/ref.md) ⟩ 'xxx' is not defined

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

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

* [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)
* [accidental global variable in sloppy mode❗️](/web/js/concept/env/js-engine/mode/sloppy-mode/accidental-global-variable-in-sloppy-mode.md)
* [function in block (FiB)](/web/js/val/func/declare/function-in-block-fib.md):exclamation:
* [dot notation (.)](/web/js/val/obj/prop/access/dot-notation-..md) - when `obj` is [undeclared](/web/js/grammar/token/id/undeclared.md).
  {% endtab %}

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

* [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 %}
  {% 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](/web/js/concept/env/js-engine/mode/strict-mode/eval-has-its-own-scope-in-strict-mode.md)
  * [accidental global variable in sloppy mode❗️](/web/js/concept/env/js-engine/mode/sloppy-mode/accidental-global-variable-in-sloppy-mode.md)
    {% endtab %}

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

* [⛔️ ReferenceError](/web/js/err/ref.md) is a [runtime error](/web/js/err/runtime.md).
  {% endtab %}
  {% endtabs %}
