A closure is a function that retains access to its lexical scope even when invoked outside its parent scope.
Solution Code
JavaScript
function outer() { const x = 5; return function inner() { return x; }; }
Explanation
Closures preserve variables in their lexical environment through a reference chain.Guided Hints
What happens to variables after their function completes?
How do functions maintain access to parent scope?