Anonymous Functions
Intermediate · Functions & Errors
A function literal can be defined inline and assigned, passed, or returned. When it references variables from the enclosing scope it becomes a closure — it keeps those variables alive and can mutate them across calls.
Resources
Section titled “Resources”Exercises
Section titled “Exercises”anonymous_functions1 compile
Section titled “anonymous_functions1 compile”Pass an argument to an anonymous function.
Show hint
The function needs a string to print.anonymous_functions2 compile
Section titled “anonymous_functions2 compile”Match a closure’s signature and use its argument.
Show hint
You should call the function with a parameter.anonymous_functions3 compile
Section titled “anonymous_functions3 compile”Return a closure that remembers state across calls.
Show hint
1 - The `updateStatus()` function should return an order status index like `orderStatus[index]`.2 - You may need to call `anonymous_func` once more.