Lesson content
Read, practise, then check your understanding
Functions are values. Declarations are hoisted; expressions are created when execution reaches them. Arrow functions are compact and capture this, arguments, and super lexically.
Multiple forms
function factorial(n) {
if (n < 0) throw new RangeError("n must be non-negative");
return n <= 1 ? 1 : n * factorial(n - 1);
}
const double = value => value * 2;
const total = (...values) => values.reduce((sum, value) => sum + value, 0);
Default parameters activate for undefined, not null. Rest parameters collect real arrays. JavaScript passes values; object-reference values allow shared mutation. Use normal methods when dynamic receiver this matters, arrows for lexical callbacks, and higher-order functions for reusable policy. Deep recursion can overflow because tail-call optimization is not broadly available.
Knowledge check
Answer every question correctly to complete this chapter.
0 of 10 checks passed
Your progress is saved on this device.