Functions and Scope
Design functions with clear contracts, return values, lexical scope, and focused responsibilities.
Lesson introduction
A function is a reusable contract: named inputs, a defined transformation, and an observable return value or effect. Lexical scope determines which surrounding bindings the function can access. Fewer hidden dependencies make functions easier to test.
Where this fits
This lesson builds one part of the path from language fundamentals to complete browser applications.
What you will build
Name the feature that lets an inner function retain access to its outer lexical environment.
You will first study the underlying rule, then trace worked code, repair a mistake, and create an independent solution.