Comprehensive developer masterclass.
A closure is a function bundled together with references to its surrounding lexical environment, allowing private data encapsulation.
function createCounter() {
let count = 0;
return () => ++count;
}
const counter = createCounter();