> 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/closure/examples/closure-to-close-over-or-not.md).

# closure: to close over or not

[JS](/web/js.md) ⟩ [value](/web/js/val.md) ⟩ [function](/web/js/val/func.md) ⟩ [closure](/web/js/val/func/closure.md) ⟩ [example](/web/js/val/func/closure/examples.md) ⟩ to close over or not:question:

{% hint style="info" %}
even an <mark style="color:yellow;">**outer variable**</mark> is <mark style="color:red;">**not**</mark>**&#x20;**<mark style="color:yellow;">**mentioned explicitly**</mark> in a closure, it is <mark style="color:yellow;">**still being closed over**</mark> by the closure:exclamation:
{% endhint %}

{% tabs %}
{% tab title="💾 程式" %}

* replit：[to close over or not?](https://replit.com/@pegasusroe/closure-to-close-over-or-not#index.js)

```javascript
// • returns a closure
// • parameters are closed over
function GetInfo(id, name, grade) {
    // ⭐ closure
    // although `id`, `name`, `grade` are not mentioned explicitly,
    // these parameters are still being closed over by the closure.
    return function getInfo(whichValue) {
        // ⭐ eval('id') returns `id`, etc ...
        return eval(whichValue);
    };
}

const info = GetInfo(73, "Suzy", 87);
info("name"),    // Suzy
info("grade"),   // 87
```

{% 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.7 > [Per Variable or Per Scope?](https://github.com/getify/You-Dont-Know-JS/blob/2nd-ed/scope-closures/ch7.md#per-variable-or-per-scope)
  {% endtab %}
  {% endtabs %}
