Javascript Closure - Click Counter Example
by nkdweb
JavaScript
function clickCounter() {
var counter = 0;
function runCounter() {
return counter += 1;
};
return runCounter;
}
var counter = clickCounter();
alert(counter()); // 1
alert(counter()); // 2
alert(counter()); // 3