Closure in JavaScript
A closure is the combination of a function and the lexical environment within which that function was declared.
A closure is an inner function that has access to the outer enclosing function's variable scope chain.
A closuer can access its own variables, outer functions variables and global variables.
We can create a closure by adding a function inside another function.
function show() { var name = 'My Name'; // name is a local variable created by show function displayName() { // displayName() is the inner function, a closure alert(name); // use variable declared in the parent function } displayName(); } show();