Closures
Function expressions are evaluated to closure
literals. This means that the closure captures the environment at the
time of declaration, not at the time of invocation. In this example, the add1 function captures the value of one
at the time of declaration, not at the time of invocation.
In Python, the same code would raise an error because the one
variable is redefined before the add1 function is called.
one = 1
add1 = lambda x: x + one
one = None
add1(2)