Functions & Programming Concepts · Level 2 of 5
Closure
A callable that retains access to bindings from its surrounding scope.
Capture semantics determine whether values or references are retained.
Example
A returned function remembers the multiplier supplied when it was created.
Listen to the definition and example
Audio transcript
Closure. A callable that retains access to bindings from its surrounding scope. Capture semantics determine whether values or references are retained. For example: A returned function remembers the multiplier supplied when it was created.
Explore this concept
A useful analogy
A function carrying a backpack of surrounding bindings it may need later.
Why it matters
This helps you distinguish a computation’s contract, inputs, outputs, and behavior.
Technical detail
A closure pairs executable code with an environment. Captures may retain references, which can affect lifetime and later behavior.
Related concepts
Quick recall question
Try answering before looking back at the definition.