Created
May 26, 2024 19:46
-
-
Save b-tekinli/5ab582abfc4844df2a57ae7989e3d0d3 to your computer and use it in GitHub Desktop.
js interview closure
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 createCounter() { | |
let count = 0; // Bu değişken dışarıdan erişilemez. | |
return function() { | |
count++; // İç fonksiyon dıştaki 'count' değişkenine erişebilir. | |
return count; | |
}; | |
} | |
const counter = createCounter(); | |
console.log(counter()); // 1 | |
console.log(counter()); // 2 | |
console.log(counter()); // 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment