A closure is a function...
A closure is not a function. A closure is "the combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment)". This is a subtle distinction, but it needs to be made to stop people ending up with the mistaken belief that a closure is a special kind of function.
a closure is created when a function is defined inside another function,
This isn't correct. ALL functions have an associated closure, regardless of whether they were created inside another function.
From MDN:
In JavaScript, closures are created every time a function is created, at function creation time.
I'm not sure why so many people get this wrong.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
A closure is not a function. A closure is "the combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment)". This is a subtle distinction, but it needs to be made to stop people ending up with the mistaken belief that a closure is a special kind of function.
This isn't correct. ALL functions have an associated closure, regardless of whether they were created inside another function.
From MDN:
I'm not sure why so many people get this wrong.