write closure function code example
Example 1: closures in javascript
function init() {
var name = 'Mozilla'; // name is a local variable created by init
function displayName() { // displayName() is the inner function, a closure
alert(name); // use variable declared in the parent function
}
displayName();
}
init();
Example 2: closure in javascript
A closure is a function bundeled together with its lexical scope