A closure is a function that "remembers" the environment in which it was created. In JavaScript, closures are created every time a function is created. A closure gives you access to the outer function’s scope from an inner function. In other words, a closure is a combination of a function and the lexical environment within which that function was declared.
Closures are essential because they enable powerful and flexible programming techniques. They allow you to: