Function Parameters & Arguments
EasyIn plain terms
Parameters are the names in the function definition. Arguments are the values passed when calling. JavaScript does not check the number - extra args are ignored, missing ones become undefined.
What you need to know
- •Parameters = definition
- •Arguments = call values
- •No type or count checking
Try it yourself
Copy the code below and run it in your browser console or a code editor:
function greet(name, greeting) {
return (greeting || 'Hello') + ', ' + name;
}
greet('Bob'); // "Hello, Bob"
greet('Bob', 'Hi'); // "Hi, Bob"
greet('Bob', 'Hi', 1); // Extra arg ignored
// arguments object (legacy)
function sum() {
let total = 0;
for (let i = 0; i < arguments.length; i++) {
total += arguments[i];
}
return total;
}Learn more
Dive deeper with these trusted resources: