Skip to main content

ClosureInternal Property of function to preserve access to VE of EC at its creation

aka Closures

Closures are an intangible property

automatic feature NOT accessible from Code, view under logs via console.dir()

the scope chain is preserved through closure, even after its execution context is gone and destroyed

!snippet eg closure - HOC returns function

function increment() {
let counter = 0;
return function() {
counter++;
console.log(counter);
};
};

new assigned function has access to counter

const closureTicker = increment();
closureTicker();closureTicker();

counter accessible via returned function due to closure

References

  1. [**_Closures_**](closure) are an **_intangible property_** ↔ automatic feature NOT accessible from Code, view under logs via console.dir()