JSworkingevergreen

Closures and the module pattern

Functions that remember.

A closure is a function bundled with the variables it was born in — the foundation of private state, factories, memoization, and the classic module pattern.

A counter factory

JSintro
Press Run to execute

a ends at 2 and b at 99 because each makeCounter call closes over its own count — proof that the two counters hold completely independent state.