JavaScript
JavaScript ClosuresJavaScript Closures
JavaScript closures allow functions to remember their outer variables.
Read Time
5 min readDifficulty
BeginnerLast Updated
Jun 15, 2026Version
v1.0.0Introduction
JavaScript closures happen when a function inside another function remembers the variables from its parent. Even after the parent function finishes running, the inner function still has access to those original variables. Developers use this to create private data.
Example
Example
Key Points
- Closures remember variables from parent functions.
- They allow for data privacy and encapsulation.
- They are created automatically when functions are nested.
- Memory leaks can occur if closures are misused.