Introduction to closures

Premium

You already know about scope from the scope series. A closure happens when a function "remembers" variables from the scope it was created in, even after that scope has finished running. Closures are how you keep private state in JavaScript.