Skip to content

Instantly share code, notes, and snippets.

@iam-peekay
Created April 27, 2016 22:56
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 iam-peekay/bf7e95892d7429c53d5f2cc474c32ce3 to your computer and use it in GitHub Desktop.
Save iam-peekay/bf7e95892d7429c53d5f2cc474c32ce3 to your computer and use it in GitHub Desktop.
function numberGenerator() {
// Local “free” variable that ends up within the closure
var num = 1;
function checkNumber() {
console.log(num);
}
num++;
return checkNumber;
}
var number = numberGenerator();
number(); // 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment