Skip to content

Chapter 7 of 33

Functions

Master declarations, expressions, arrows, parameters, recursion, and higher-order functions.

40 minutes 10 quick checksBy Subha Prasad
Lesson 7 of 33Course navigation

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.

Which statement best describes function declaration?
Which JavaScript term matches this description: A named hoisted function definition.
Which statement best describes function expression?
Which JavaScript term matches this description: A function created within an expression and assigned or passed as a value.
Which statement best describes arrow function?
Which JavaScript term matches this description: A compact callable with lexical this and no own arguments.
Which statement best describes recursion?
Which JavaScript term matches this description: A function calling itself with progress toward a base case.
Which statement best describes rest parameter?
Which JavaScript term matches this description: A final parameter collecting remaining arguments into an array.

0 of 10 checks passed

Your progress is saved on this device.