A closure is the set of local variables that are kept alive after a function call* has completed, because those variables may still be required by a local function, and a reference to a local function has somehow been exported during the function call.
The local function can be returned by the enclosing function, that’s one way of exporting its reference, but there are other common ways too, the local function can be attached to an event, pushed onto an array, anything to prevent it from being dereferenced once the enclosing function has completed.
-
doesn’t have to be functions, it can be any execution context, but let’s just leave it at function calls for now, shall we?
A closure is effectively all the stuff that belongs to an expired execution context that cannot yet be discarded because there are still references to it.