Stage 1 · Lesson 5 of 10
Closures
A is a function that remembers the variables from the place where it was created. It keeps them even after the outer function has finished. This works because of lexical : a function can see the variables written around it.
For example, function counter() { let n = 0; return () => ++n; } gives you a function with its own private n that goes up on each call. Closures are everywhere in JavaScript. , passed to map and filter, timers and React hooks all rely on them.
Common trapa loop that creates functions. With let, each pass gets its own variable. With the old var, all passes share one, so every callback sees the last value. Learning closures now, before any , is what the stage advice means by avoiding years of confusion.
A question to check yourself, an AI practice session and 2 cheat sheet entries come when you add the roadmap to your account. Add it
Resources for this stage
Start with· follow one of these
- CoursePaidGrokking JavaScript Fundamentals
Design Gurus · Beginner · $50
The language itself, closures and async included, with runnable exercises per lesson
- GuideFreeJavaScript.info
Ilya Kantor
Free: Part 1 is the most complete modern JavaScript tutorial, with tasks per chapter