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.
This article was originally published on my blog, as part of the Quickly Explained series.
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 exist 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 CLAP ON IT? If you want to read more JS articles like this, head over to my blog.