> 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/val/func/expr/named.md).

# named function expression

🚧 施工中

[JS](/web/js.md) ⟩ [value](/web/js/val.md) ⟩ [function](/web/js/val/func.md) ⟩ [expression](/web/js/val/func/expr.md) ⟩ named

{% hint style="info" %}
a [function expression](/web/js/val/func/expr.md) with an <mark style="color:yellow;">**internal name**</mark>.
{% endhint %}

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

* replit：[named function expression](https://replit.com/@pegasusroe/named-function-expression#index.js)

{% hint style="warning" %}

* <mark style="color:blue;">`outerName`</mark> is in the <mark style="color:yellow;">**outer**</mark> [scope](/web/js/scope.md)
* <mark style="color:blue;">`innerName`</mark> is in the <mark style="color:yellow;">**inner**</mark> "<mark style="color:orange;">**implied scope**</mark>".
  {% endhint %}

```javascript
// ⭐ named function expression
// ------------------------------------
//                       ╭──name──╮
var outerName = function innerName() {
    console.log(innerName);
    //          ^^^^^^^^^ <---- ⭐ visible from inside
};

outerName();      // [Function: innerName]

outerName.name,   // "innerName"
innerName,        // ⛔ ReferenceError: `innerName` is not defined
                  //    (⭐ `innerName` invisible from outside)
```

{% endtab %}

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

* [ ] [YDKJS: Scope & Closures (v.2)](/web/master/ref/book/you-dont-know-js-series-v.2/ydkjs-scope-and-closures-v.2.md) ⟩ Ch. 3: [The Scope Chain](https://github.com/getify/You-Dont-Know-JS/blob/2nd-ed/scope-closures/ch3.md#chapter-3-the-scope-chain)
  {% endtab %}

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

* [ ] [Function expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/function)&#x20;
  {% endtab %}

{% tab title="🚧" %}

* [ ] implied scope
  {% endtab %}
  {% endtabs %}
