Closure - 09

A closure gives you access to an outer function’s scope from an inner function.

To use a closure, define a function inside another function and expose it. To expose a function, return it or pass it to another function.

function makeFunc() { 
var name = 'Mozilla'; 
     function displayName() { 
     alert(name); 
     } 
     return displayName; 
} 
var myFunc = makeFunc(); 
myFunc()



Post a Comment

Previous Post Next Post