what are Function closures code example
Example 1: closures in javascript
function OuterFunction() {
var outerVariable = 100;
function InnerFunction() {
alert(outerVariable);
}
return InnerFunction;
}
var innerFunc = OuterFunction();
innerFunc();
Example 2: javascript closure function example
function makeFunc() {
var name = 'Mozilla';
function displayName() {
alert(name);
}
return displayName;
}
var myFunc = makeFunc();
myFunc();
Example 3: closures in javascript
function init() {
var name = 'Mozilla';
function displayName() {
alert(name);
}
displayName();
}
init();