Monday, July 18, 2016

JavaScript - Closure



mycount variable act as Global variable

function getCounter() {
   var myCount = 0;
   return function() {
        return myCount++;
    }
}

counter = getCounter();


> counter();
0
> counter();
1

No comments: