Created
July 29, 2020 08:09
-
-
Save akumbhani66/200c9e103ffa9f1b00cfc8975e61be6d to your computer and use it in GitHub Desktop.
Simple closure example
This file contains hidden or 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 getCounter() { | |
let counter = 0; | |
return function () { | |
counter = 1; | |
return function () { | |
return counter = 2; | |
} | |
} | |
} | |
let count = getCounter(); | |
let count2 = count(); | |
console.log(count2()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment