Skip to content

Instantly share code, notes, and snippets.

@dvidsilva
Created May 8, 2013 23:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvidsilva/5544467 to your computer and use it in GitHub Desktop.
Save dvidsilva/5544467 to your computer and use it in GitHub Desktop.
Javascript functions are first class citizens just like any object, they can access the variables declared before them
var makeCounter = function(){
var n=0;
return function(){
return n = n + 1;
}
}
var counter1 = makeCounter();
var counter2 = makeCounter();
counter1();
counter1();
counter1();
counter2();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment