What Are Closures?

closures in Javascript

        closures in Javascript

(function() {
    function foo(x) {
        var baz = 3;
        return function (y) {
        console.log(x + y + (++baz));
        }
    }
var moo = foo(2); // moo is now a closure.
moo(1); // 7
moo(1); // 8!
})();

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *