Created
January 11, 2016 15:43
-
-
Save mmloveaa/34817d1ac67e9cc28cd2 to your computer and use it in GitHub Desktop.
Closure - twice
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
// 1/5/2016 | |
// write a function that will only increment a value twice | |
// value starts at 0 | |
// var twice = createFunc() | |
// twice() => 1 | |
// twice() => 2 | |
// twice() => 2 | |
// twice() => 2 | |
// function createFunc() { | |
// var value = 0; | |
// function increment() { | |
// if (value < 2) { | |
// value++ | |
// console.log(value) | |
// } | |
// else { | |
// console.log('this shouldnt run because value is already two ', value) | |
// } | |
// } | |
// return increment | |
// } | |
// var twice = createFunc() | |
// twice() | |
// twice() | |
// twice() | |
// twice() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice