Last Updated on
A closure happens when one function is inside another function, and the inner function wants to access a variable which belongs to the outer function.
The floor is like the main function scope or the global scope.
Every time you create a new function, it will be like a bucket.
All the variables you create inside that bucket (function) will only be accessible within that bucket only.
You can create a function inside another function, or to say bucket inside another bucket.
For this reason an outer function won’t have access to a variable which was inside another function. Because by the time the function gets its chance, the inner function does not exists anymore.
What happens when there is a variable in a function, which the inner function wants to use?
Hey did you found this article helpful?
Why don’t you quickly tap on one of those share buttons to quickly share this article with your JS friends?