Closure in JavaScript 🔥
It took some time for me to comprehend, but I believe I have grasped the concept of it.
Essentially, Closure refers to a function bundled together with its lexicon environment, meaning a function with its lexicon scope.
Why is Closure important 🤓?
It allows for inner functions to access another function’s scope.
In JavaScript, functions can be manipulated quite freely.
They can be assigned to a variable.
Passed as a parameter to another function.
And even returned in a function.
Closure can become difficult to understand when a function is returned within a function.
In this scenario, the function retains its lexicon scope and remembers where it was initially present, such as pointing to the value of “a.”
This is an easy example 🫠 but it lays down the fundamentals of Closure in JavaScript.
I do think they should have chosen another name for this concept though 😆.