What is the purpose of closures in JavaScript?

What is the purpose of closures in JavaScript?

When you create a function, the code in the function can access variables/the scopes that exists outside the function. The closure makes sure those variables/scopes outside the function exist as long as the function exist. So even if the code execution leaves the scope in which the function was created, that scope will continue to exist as long as the function exist.

The article on MDN does a good job of explaining them.