Learning object 14 of 100
Function argument explorer
Write a parameter list and a call, and see which parameter receives each argument, which ones use a default, which are undefined and which extra arguments are ignored.
Loading…
What it shows
Arguments fill parameters by position. Missing arguments are undefined, and a default parameter replaces undefined (but not null). Extra arguments have no name unless a rest parameter (...rest) collects them into an array.
Guided experiment
- Choose Missing argument and then Default used. What changes?
- Choose undefined vs null and explain why only one default applies.
- Add a rest parameter to Extra arguments and call again.
Predict
function f(a, b = 2) {} is called as f(1, null). What is b?
Related
Lessons: Lesson 22: Parameters and arguments, Lesson 24: Arrow functions
Projects: Project 1: Interactive Tip Calculator
Source: web/assets/js/objects/object-014.js in the companion repository.