Closure Variable Capture
Multiple Choice Medium
Question
In a closure, when is the outer variable accessed?
Hint
Closures capture by reference.
Explanation
Closures capture variables by reference, not by value. The inner function accesses the current value of the outer variable when it executes, not when it was defined. This is why loop closures often need let (block scope) or IIFEs to capture the correct iteration value.
Related Resources
Related Lessons
- Functions
Learn JS functions.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.