Verified Jobs Live
JavaScript & Web Technologies Easy Level ~3 min read

What is a closure? Show a practical example.

Interactive Practice Mode
Formulate your thoughts or take notes before revealing the model solution.
Model Answer & Deep-Dive Explanation

A closure is a function together with access to its surrounding lexical environment. The function can use those variables even after the outer function has retu ed. A counter factory can create independent counters without exposing a writable global variable. Closures also support event handlers and configurable functions. They capture bindings rather than frozen snapshots of every value, so later changes can affect what the function sees. Long-lived closures can keep referenced objects reachable, which matters when investigating memory growth.