JS Function Parameters vs Arguments Differences
Parameters are placeholders. Arguments are actual values. Learn the difference, why it matters, and how JavaScript handles argument mismatches without throwing errors.
The difference between a parameter and an argument can be summed up in one sentence: a parameter is a named placeholder in the function definition, and an argument is the actual value passed when calling the function.
Here it is in one clear example:
// price and quantity are PARAMETERS (placeholders)
function calcTotal(price, quantity) {
return price * quantity;
}
// 19.99 and 3 are ARGUMENTS (actual values)
calcTotal(19.99, 3); // 59.97The names are defined once when you write the function. The values change every time you call it. That distinction is simple but important.
Quick Comparison
| Parameter | Argument | |
|---|---|---|
| Where | In the function definition | In the function call |
| What it is | A named variable placeholder | A concrete value or expression |
| When set | When the function is defined | When the function is called |
| Lifetime | Lives inside the function body | Evaluated once per call, then bound to the parameter |
| Example | In function foo(x, y), x and y are parameters | In foo(10, 20), 10 and 20 are arguments |
Why the Distinction Matters
If you mix up parameters and arguments, you might write confusing explanations in code reviews or misread error messages. But the practical reason the distinction matters is that JavaScript handles mismatches between them silently.
If you pass fewer arguments than there are parameters, the extra parameters become undefined. If you pass more, the extras are ignored by the named parameters but still accessible.
Understanding this behavior lets you debug function calls that do not behave as expected.
What Happens When Arguments Do Not Match Parameters
Fewer Arguments Than Parameters
function introduce(name, age, city) {
console.log(`${name} is ${age} and lives in ${city}.`);
}
introduce("Alex", 25);
// "Alex is 25 and lives in undefined."No error. The city parameter is undefined. JavaScript fills parameters left to right, so calling a function expecting three values with only two leaves the third slot empty.
More Arguments Than Parameters
function showFirst(a) {
console.log(a);
}
showFirst(10, 20, 30);
// 10No error. The extras (20 and 30) are silently ignored by the named parameter. But they are not lost, you can still access them through the arguments object in regular functions:
function showAll(a) {
console.log("Named parameter:", a);
console.log("All arguments:", arguments);
}
showAll(10, 20, 30);
// Named parameter: 10
// All arguments: [Arguments] { '0': 10, '1': 20, '2': 30 }Passing by Value vs Passing by Sharing
When you pass a primitive as an argument, the function gets a copy. Changing the parameter inside the function does not affect the original:
function changeValue(x) {
x = 100;
console.log("Inside:", x);
}
let num = 5;
changeValue(num); // Inside: 100
console.log(num); // 5 -- unchangedWhen you pass an object, the function gets a reference. Mutating the object's properties affects the original, but reassigning the parameter does not:
function updateCar(car) {
car.color = "blue"; // Mutates the original object
car = { color: "red" }; // Reassigns the local parameter only
}
const myCar = { color: "black" };
updateCar(myCar);
console.log(myCar.color); // "blue" -- mutated, not reassignedThis is called pass by sharing. The parameter holds a reference to the same object, so property changes are visible outside. But reassigning the parameter variable itself only changes the local binding.
| Argument type | What the function receives | Reassignment inside the function | Mutation inside the function |
|---|---|---|---|
| Primitive (number, string, boolean) | A copy of the value | Has no effect on the original | Not possible, primitives cannot be mutated |
| Object or array | A reference to the same object | Only changes the local variable | Visible on the original object |
Default Parameters: Handling Missing Arguments
Instead of checking for undefined inside the function body, you can set default values directly in the parameter list:
// Without defaults (old way)
function greet(name) {
name = name || "Guest";
console.log(`Hello, ${name}!`);
}
// With defaults (modern way)
function greet(name = "Guest") {
console.log(`Hello, ${name}!`);
}
greet(); // "Hello, Guest!"
greet("Sara"); // "Hello, Sara!"The default only activates when the argument is undefined, not for other falsy values like null, 0, or "". Learn more in How to Use Default Parameters in JS Functions.
For a broader introduction to functions, see What Is a Function in JavaScript Beginner Guide.
Common Beginner Mistake: Naming Confusion
Beginners often say "I passed the parameter 5" when they mean "I passed the argument 5." In casual conversation, people understand. But in technical discussions, the wrong term can cause confusion, especially when discussing function signatures, TypeScript types, or API design.
A simple rule to remember:
- If you are writing the function, you are working with parameters.
- If you are calling the function, you are working with arguments.
Arguments in Arrow Functions
Arrow functions do not have their own arguments object:
const show = () => {
console.log(arguments);
};
show(1, 2, 3); // ReferenceError: arguments is not definedIf you need to capture all arguments in an arrow function, use rest parameters instead. A rest parameter collects every argument into a real array, which arrow functions can read normally:
const show = (...args) => {
console.log(args); // [1, 2, 3]
};
show(1, 2, 3);Where to Go Next
Parameters are the named slots you define in a function signature, and arguments are the real values that fill those slots at call time. Keeping that distinction straight makes it easier to debug mismatched calls and read function signatures in any codebase.
Rune AI
Key Insights
- Parameters are the names in the function definition. Arguments are the values in the function call.
- Missing arguments become undefined. Extra arguments are accessible through the arguments object.
- Object and array arguments are passed by sharing, meaning mutations inside the function affect the original.
- Use default parameters to handle missing arguments gracefully.
- The arguments object is only available in regular functions, not arrow functions.
Frequently Asked Questions
Can I use the words parameter and argument interchangeably?
Does JavaScript throw an error for missing arguments?
What is the arguments object?
Conclusion
Parameters and arguments are two sides of the same coin. Parameters are the named slots you define in a function signature. Arguments are the real values that fill those slots at call time. Understanding the distinction helps you write clearer code, debug argument mismatches, and explain function behavior to other developers.
More in this topic
JavaScript While Loop Explained: A Complete Guide
A while loop repeats code as long as a condition stays true. Learn the syntax, see practical examples, and understand when a while loop is the right choice over a for loop.
JavaScript Loops Tutorial: for, while, do while
Loops let JavaScript repeat code without writing it twice. Learn the three core loop types, what each one does, and when to choose one over another.
How to Loop Through Arrays Using JS for Loops Guide
Looping through arrays is the most practical use of JavaScript for loops. Learn how to access each element by index, avoid off-by-one errors, and choose between for, for...of, and forEach.