ADVANCE FUNCTIONS JS

 A function has access to the variable environment (VE) of excecution context it was created 

Closure: VE attached to the function, exactly as it was at the time and place the function was created 

A closure is the combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment). In other words, a closure gives you access to an outer function's scope from an inner function. In JavaScript, closures are created every time a function is created, at function creation time.


A closure is the closed-over variable environment of the execution context in which a function wascreated, even after that execution context is gone.

A closure gives a function access to all the variables of its parent function, even after that parent function has returned. The function keeps a reference to its outer scope, which preserves the scope chain throught time.

A closure makes sure that a function doesn't loose connection to variable that existed at the function's birth place.

A closure is like a backpack that a function carries around wherever it goes. This backpack has all the variables that were present in the environment where the function was created.

We do NOT have to manually create closures, this is js feature that happens automatically. we can't even access closed-over variables explicity. A closure is NOT a tangible JS object  

Comments

Popular posts from this blog

Events Js