Created
April 25, 2016 13:29
-
-
Save ChrisMoney/d34046e8f2f265b243f479d7f0d08ac7 to your computer and use it in GitHub Desktop.
Javascript - Closure
This file contains hidden or 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
var add = (function () { | |
var counter = 0; | |
return function () {return counter += 1;} | |
})(); | |
add(); | |
add(); | |
add(); | |
// the counter is now 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example Explained
A closure is a variable assigned to a function.