A factory call creates a local count binding and returns an inner function that reads count. The factory call has finished. Why can the inner function still read count?
Explanation
The returned inner function closes over the lexical environment in which it was created, retaining access to count after the factory call ends. The caller's current local variables do not replace that environment, because this access is lexical rather than caller-based.