Closures are one of the most powerful and often misunderstood features of JavaScript. A closure gives you access to an outer function’s scope from an inner function.
function createCounter() { let count = 0; return function() { count += 1; return count; }; } const counter = createCounter(); console.log(counter()); // 1