How do JavaScript closures work?

Closures allow an inner function to access variables from an outer function.

function outer() {
  let count = 0;
  return function() {
    count++;
    return count;
  };
}
const increment = outer();
increment(); // 1
increment(); // 2