Skip to content

Instantly share code, notes, and snippets.

@erockdotdev
Last active July 1, 2020 00:12
Show Gist options
  • Save erockdotdev/5d003e673715dcad66a8eb9f428f983f to your computer and use it in GitHub Desktop.
Save erockdotdev/5d003e673715dcad66a8eb9f428f983f to your computer and use it in GitHub Desktop.
function outterFunction() {
let score = 0;
return function innerFunctio() {
if (score === 0) {
console.log("you have no points");
} else {
console.log(`you have ${score} points`);
}
score += 1;
};
}
const lookMahImAClosure = outterFunction();
console.log(lookMahImAClosure());
// you have no points
console.log(lookMahImAClosure());
// you have 1 points
console.log(lookMahImAClosure());
// you have 2 points
console.log(lookMahImAClosure());
// you have 3 points
console.log(lookMahImAClosure());
// you have 4 points
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment