Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Closure - twice
// 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()
@mdsaimon

This comment has been minimized.

Copy link

mdsaimon commented Jan 11, 2016

nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.