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

# named function expression

[JS](../../..) ⟩ [value](../..) ⟩ [function](..) ⟩ [expression]() ⟩ named

{% hint style="info" %}
a [](<> "mention") 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](../../../scope "mention")
- <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-and-closures-v.2](../../../../master/ref/book/you-dont-know-js-series-v.2/ydkjs-scope-and-closures-v.2 "mention") ⟩ 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 %}
