AI-powered
podcast player
Listen to all your favourite podcasts with AI-powered features
Closure in JavaScript
A closure is a function that returns a function with its own scope. In TypeScript, it's able to access the outer scope of the parent function so that you can sort of carry around data by calling that function over and over again. The big example is always like a counter, right? You have a function called make counter, and then that returns an increment function. Every single time you run that increment function, it still has access to this invisible variable of the upper scope.