Last active
July 1, 2020 00:12
-
-
Save erockdotdev/5d003e673715dcad66a8eb9f428f983f to your computer and use it in GitHub Desktop.
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
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