Closures
Lambdas or nested functions can capture variables from outer scopes, and even after the outer function has returned, the captured variables remain accessible. This combination of function and captured variables is called a closure.
Variable capture occurs when the closure is defined, and captured variables must already be initialized. Captured variables "escape" from their original scope along with the closure, so they can be used to create stateful functions.
In the example on the right, makeAdder returns a lambda that captures the base parameter. Each call to makeAdder creates an independent closure, each holding different captured values. makeGreeter is similar, where the returned function captures prefix.
If a closure captures a mutable variable declared with var, the closure cannot be used as a first-class citizen (cannot be assigned, returned, or passed as parameter), and can only be called directly. This is to prevent data races.
Try calling makeAdder(20) to create a new adder and verify that it is independent of add10.