Anonymous functions can be created with the fn keyword:
fn
fn (x) { x * x };
Functions can be passed as variables, or immediately invoked as here:
fn (x) { x * x } (5); // 25
You can of course name your functions by assigning them:
factorial = fn (n) { if (n == 0) { 1 } else { n * factorial(n - 1) } }
The fn keyword can take a function name, so:
fn factorial(n) { if (n == 0) { 1 } else { n * factorial(n - 1) } }
is completely equivalent.
Next: Closure
There was an error while loading. Please reload this page.