JavaScript Closures Explained by Mailing a Package — Free Code Camp

If you have mailed a package or letter in the past, then you can understand closures in JavaScript.

On your journey to becoming an intermediate or advanced JavaScript dev, you may have come across closures. After reading a technical resource on the subject… you also probably ran in the opposite direction.

Here is the awesome thing about closures: they allow you to write functions with an intermediate step that can capture data from your site at a specific moment in time. It’s like adding a ‘pause’ button to your function. You can run your function and save a variable that represents the state of the app at that point in time. Then, when you want to resume the function at a later point with a new value based on a change of state in the app… you can do that with a closure, or a function within the original function.

This gets easier, I promise.

Source: JavaScript Closures Explained by Mailing a Package — Free Code Camp