DEV Community

Discussion on: Closures: A Powerful Concept in JavaScript

Collapse
 
koushikmaratha profile image
koushikmaratha

Hi, @jonrandy

The statement "a closure is not a function" is true in the sense that a closure is not a standalone entity that can be invoked like a function. Rather, a closure is a behavior that arises from the way functions access variables from their outer lexical scope.

So, When a function accesses a variable from its outer scope, a reference to that variable is stored in the function's closure. This allows the function to maintain access to the variable even after the outer scope has been destroyed. In essence, a closure is a way for a function to "remember" the state of its outer scope at the time it was created.

Therefore, while a closure is not a standalone function, it is a behavior that is closely tied to the way functions work and their access to variables in their outer lexical scope.