The two biggest (and unfortunately widespread) misconceptions about closures:
This is entirely wrong for two reasons:
- Closures are not functions
- ALL functions have access to their surrounding scope*
Again, entirely wrong - nesting of functions is irrelevant! Whenever a function is created, an associated closure is also created.
A closure is the combination of a function bundled together (enclosed) with references to its surrounding state
The closure allows the function to access the state in which it was created.
*Except for functions created with
new Function(...) which form closures with the global scope