RSS

Monthly Archives: April 2013

What is JavaScript Closure?

Whenever the inner function (a nested function) have access to variables defined outside of the inner function;s scope.

function SayHello(name) {
    // 'text' is local variable to 'SayHello'
    var text = 'Hello ' + name;

    // 'SayAlert' function has access to 'text' variable.
    var SayAlert = function() { alert(text); }

    return SayAlert;
}
Advertisements
 
Leave a comment

Posted by on April 2, 2013 in General

 

Tags: ,

 
%d bloggers like this: