Inputs to Functions
Parameters are the named variables in the function definition.
Arguments are the actual values passed when you call the function.
JavaScript Tutorial
Parameters are the placeholders in a function definition, and arguments are the values you pass in.
Understanding the difference makes function calls clearer and safer.
Most bugs in functions come from unexpected inputs or missing values.
Clear parameter handling keeps your functions predictable.
function name(param1, param2) { ... }
name(arg1, arg2)function greet(name) {
return "Hello " + name;
}
console.log(greet("Neha"));name is a parameter, and 'Neha' is the argument.
function label(status) {
return status ?? "pending";
}
console.log(label());Missing arguments become undefined.
Parameters are the named variables in the function definition.
Arguments are the actual values passed when you call the function.
If an argument is missing, its parameter becomes undefined.
Use default parameters to handle missing values safely.
JavaScript does not enforce parameter count. Extra arguments are ignored unless you capture them.
Use rest parameters to collect extra values.
function add(a, b) {
return a + b;
}
console.log(add(2, 3, 4));Extra arguments are ignored unless you collect them.
function sum(...nums) {
return nums.reduce((acc, n) => acc + n, 0);
}
console.log(sum(1, 2, 3));Rest parameters collect extra arguments into an array.
Without
function greet(name) {
return "Hello " + name;
}
console.log(greet());With
function greet(name = "Guest") {
return "Hello " + name;
}
console.log(greet());Validate inputs or provide defaults.
Arrow functions do not have their own arguments object.
Keep parameter order stable and well-documented.
A named input in a function definition.
The actual value passed to a function call.
Use rest parameters to capture them.
Practice: Write a function that takes two parameters and returns their difference.
// TODO: function diff(a, b)
One Possible Solution
function diff(a, b) {
return a - b;
}
console.log(diff(10, 4));Parameters are named inputs; arguments are the values passed.
Missing parameters become undefined.
Yes, extra arguments are ignored unless you capture them.
Try passing different arguments and see how outputs change.