Technical skill practice
JavaScript Function Arguments: Parameters, Rest and Extra Values
Parameters are the names in a function definition; arguments are values supplied by a call. A call can supply more or fewer values than there are named parameters. Decide what the function should do with those possibilities.
The task
Inspect a report function with one named parameter and a rest array. Compare an omitted argument with an explicit undefined value using the actual call count.
Runnable Node 22 example
const assert = require('node:assert/strict');
function inspect(title, ...extra) {
return {title, extra, supplied: arguments.length};
}
assert.deepEqual(inspect('weekly', 4, true), {title: 'weekly', extra: [4, true], supplied: 3});
assert.deepEqual(inspect(), {title: undefined, extra: [], supplied: 0});
assert.deepEqual(inspect(undefined), {title: undefined, extra: [], supplied: 1});
console.log(JSON.stringify(inspect('weekly', 4, true)));
Expected output and explanation
The named title parameter receives the first supplied value. Rest collects the remaining values into an array, so four and true remain separate elements rather than being silently discarded. arguments.length records how many values the ordinary function call supplied.
The empty call and explicit undefined call produce the same title value but different counts. That distinction can matter in a deliberately defined API, although most functions should prefer a simpler contract. Default-parameter behavior is handled in the linked concept rather than inferred from this inspection.
Output from the example
{"title":"weekly","extra":[4,true],"supplied":3}
Pitfall to check
Arrow functions do not provide their own arguments object. Use rest when you want the arrow’s supplied values. Also do not expose or log arbitrary extra arguments in a real application when they may contain confidential input.
Questions, answered
Do extra arguments automatically create named parameters?
No. They can be read through rest or an ordinary function’s arguments object, but they do not invent additional parameter names.
Sources and examples
ResumizeAI team. Examples are fictional teaching material, not customer results. Replace sample details with your own facts.
Your experience. A complete resume.
Build in Resumize with ATS-friendly templates, guided editing and a live preview. Start free, then upgrade when you need more.
Free account required. Free-plan PDF exports include a watermark.