Module 4 · Lesson 3 of 415/32 in the course~18 min
Module lessons (3/4)
Default and rest parameters
Lesson preview5 hands-on exercises readyJavaScript Course · Module 4 — Functions
Default values, ...rest for variable argument counts, spread at call site.
What you'll learn in this lesson
- Set clean defaults (
param = defaultValue) and know that they only activate onundefined. - Collect an arbitrary number of arguments into a real array with the rest parameter (
...args). - Expand array into separate arguments when called with spread (
fn(...values)). - Apply destructuring with defaults directly in the feature signature for ergonomic options.
Overview
Modern functions in JavaScript handle optional parameters and flexible signatures without having to manually inspect arguments. Default parameters, rest (...rest) and spread (...arr) make signatures self-documenting.
Sections covered in this lesson
- 1Mental model:
restgathers vsspreadexpands - 2Progressive examples
- 3Guided laboratory
- 4Check for understanding
Pro Lesson · Module 4 — Functions
Unlock "Default and rest parameters" and the full JavaScript Course curriculum
Default values, `...rest` for variable argument counts, spread at call site.
Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.
- Instant access to all advanced modules in JavaScript Course plus 17 more courses
- Hands-on browser exercises with automated test suites and solutions
- 14-day money-back guarantee processed via Paddle.com
14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.