Last active
June 28, 2018 01:48
-
-
Save juan-cortes/752ed57313680f27ae527dd7ee84983f to your computer and use it in GitHub Desktop.
Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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