JavaScript · Junior · Question 19 of 75
What is a closure?
- ✓Correct answer: A function together with access to variables of the outer scope where it was created
- 2A function that is called right after declaration and then deleted
- 3A block of code in curly braces that is inaccessible from outside after it runs
Explanation
Every JS function remembers the lexical environment where it was created and can read and change its variables even after the outer function finishes. Private data, function factories, memoization and event handlers are built on this.