Skip to content

Instantly share code, notes, and snippets.

@juan-cortes
Last active June 28, 2018 01:48
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 juan-cortes/752ed57313680f27ae527dd7ee84983f to your computer and use it in GitHub Desktop.
Save juan-cortes/752ed57313680f27ae527dd7ee84983f to your computer and use it in GitHub Desktop.
Example
function count() {
var counter = 0;
return function innerCount() {
return ++counter;
}
}
var counter1 = count(); //Create a new counter
var counter2 = count(); //Create a new counter
counter1(); //returns 1
counter1(); //returns 2
counter2(); //returns 1 again, but why!?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment