Skip to content

Instantly share code, notes, and snippets.

@b-tekinli
Created May 26, 2024 19:46
Show Gist options
  • Save b-tekinli/5ab582abfc4844df2a57ae7989e3d0d3 to your computer and use it in GitHub Desktop.
Save b-tekinli/5ab582abfc4844df2a57ae7989e3d0d3 to your computer and use it in GitHub Desktop.
js interview closure
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