Hi Minh, I used "cache" or "memory" as a pointer to explain how closure works. Don't let the pointer confuses you.

What happens is that the increment function still has access to counter variable, despite of increment function being executed outside of it's scope.

On each execution, it is updating the counter, but how does it "keep" the value of counter from the previous execution?

So "keeping" the value is the power of closures, which simply means that the function can still access variables from it's birth's scope.

Thanks for reading :)

Front-end web developer and graduate student from Microverse.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store