Skip to main content

Scope & closures

Every block — if, while, repeat, and function bodies — introduces its own lexical scope, chained to its enclosing scope. Functions capture the environment they were defined in as a closure, so a function can reference variables from the scope it was declared in even after that scope has technically been left.

let y be 5
if true
let y be 100 // shadows the outer y inside this block only
show y // 100
show y // 5