JavaScript Foundations - codeandwhisky/Developer-Fundamentals GitHub Wiki
Closure Function
Situation
- We need a global variable but other functions should not be able to access/modify it - as any global variable are accessible inside functions.
- We need a local variable but that should persist previous state/value - as any local/private variables are reinitialized every time function is called.
Example
Real World Scenario