# function name scope

[JS](..)⟩ [scope]() ⟩ function name scope

{% hint style="success" %}
the <mark style="color:yellow;">**name**</mark> [id](../grammar/token/id "mention") of a [expr](../val/func/expr "mention") is in <mark style="color:yellow;">**its own**</mark> <mark style="color:purple;">**function name scope**</mark>, nested <mark style="color:orange;">**between**</mark> the <mark style="color:yellow;">**outer enclosing scope**</mark> and the <mark style="color:yellow;">**inner function scope**</mark>.
{% endhint %}

{% tabs %}
{% tab title="💈範例" %}
* replit：[function expression identifier](https://replit.com/@pegasusroe/function-expression-identifier#index.js)

```javascript
var outerName = function innerName() {

    // ⭐ shadowing `innerName` is allowed inside function body
    // -----------------------------------------------------------------------
    // if `innerName` was in the function's scope, we'd expect an error here:
    // namely, SyntaxError: Identifier 'innerName' has already been declared
    let innerName = 1234;
    
    return innerName;
};

outerName(),    // 1234
```

👉 [syntax](../err/syntax "mention") ⟩ [redeclare](../err/syntax/redeclare "mention")
{% 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") ⟩ Appendix A: [Exploring Further](https://github.com/getify/You-Dont-Know-JS/blob/2nd-ed/scope-closures/apA.md#appendix-a-exploring-further)
{% endtab %}
{% endtabs %}
