Function parameters and arguments
Quick answer
Parameters are local names in a function definition; arguments are values supplied at a call. JavaScript does not require the caller to provide exactly the declared number.
How it works
Arguments are evaluated before the call. An omitted ordinary parameter receives undefined, and extra arguments are allowed. A parameter reassignment does not reassign the caller’s variable. Objects passed as values can still share identity.
function show(a, b) { console.log(a, b); }show(4);show(4, 8, 9);Expected output in Node.js:
4 undefined4 8The omitted value is undefined; the third value has no named parameter.
function adjust(n) { n += 2; return n; }let score = 7;console.log(adjust(score), score);Expected output in Node.js:
9 7The local binding changes, not score.
Common mistakes
Missing arguments can cause NaN in arithmetic. Validate inputs when a number is required.
Practice
Write a function with two parameters and call it with zero, one, two and three arguments; predict each result.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Function parameters and arguments — Knowledge Check
Apply the taught concept and reason about the result.
In function add(a,b){return a+b;} which are the parameters?
What does function pick(a,b){return b;} called as pick(4) return?
What does function first(a){return a;} called as first(3,9) return?
If a numeric parameter is reassigned inside a function, what happens to the caller's numeric variable?
When are ordinary call argument expressions evaluated?