Closure Scope Chain
A closure is the combination of an enclosed structure with references to its surrounding state.A closure from an inner function gives us access to the domain of an external function. Closures are generated in JavaScript any time a function is created, at the time of creation of the feature. We have three scopes for each closure: Local Scope (Own scope) Outer Functions Scope Global Scope A common mistake is not to understand that in the case where the outer function is itself a nested function, access to the scope of the outer function requires the outer function enclosing domain, effectively creating a chain of function scopes. EXAMPLE // global scope let a = 10; function sum(x){ return function(y){ return function(z){ // outer functions scope ...
Comments
Post a Comment