The JavaScript Tutorial

Comprehensive developer masterclass.

Chapter 3: Lexical Scope & Closures

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();
โ† Chapter 2 Chapter 4: Async โ†’