Javascript Closures


What Is a "closure" in the JavaScript Programming Language?


In many programming languages, the variables in scope are limited to global variables, parameters, and local variables. In languages which support closures , such as JavaScript, variables may also be bound dependent on the context in which a function was declared. A closure is a function that is evaluated in its own environment, which has one or more bound variables that can be accessed when the function is called. They come from the functional programming world, where there are a number of concepts in play. Closures are like lambda functions, but smarter in the sense that they have the ability to interact with variables from the outside environment of where the closure is defined.