Javascript Closure
By Saket Bhatnagar••Beginner to Intermediate
closure
- 1A closure is created when a function is defined within another function and inner function need to access variables in the outer function's scope.
- 2Closure helps to achieve lexical scope from child function to parent function.
- 3Closure preserves the state of parent function even after the execution of parent function is completed.
- 4A child function will have reference to the closure.
- 5Every time a parent function is called the new closure is created.
- 6 Disadvantage : High memory consumption.