Parameters are the names listed in a function definition, and arguments are the actual values you pass when you call the function. In function add(a, b), a and b are parameters. In add(2, 3), the values 2 and 3 are arguments. People mix the two terms constantly, but the difference matters when you read documentation and error messages about javascript parameters and arguments.
This guide explains the vocabulary, what happens when the counts do not match, and how rest parameters and the legacy arguments object fit in.
A parameter is a variable declared in the function signature. It acts as a placeholder that is filled in each time the function runs. An argument is the real value supplied by the caller.
Here name and greeting are parameters. Each call supplies different arguments, so the same function produces different results. A simple memory aid: parameters are what the function receives, arguments are what the caller passes.
JavaScript does not check the number of arguments. There is no error for passing too few or too many.
undefined.arguments.Because of this, code often fails quietly when you forget an argument. Default parameter values or explicit checks protect against it.
A default value is used when the argument is missing or is undefined. It is not used for null, 0 or an empty string.
Defaults are covered in more detail in their own article. For now, remember that they are part of the parameter list.
A rest parameter, written with three dots, gathers all remaining arguments into a real array. It must be the last parameter.
Use rest parameters when a function accepts any number of arguments. The opposite operation, the spread syntax, expands an array into separate arguments at the call site: sum(...[1, 2, 3]).
Regular functions have an array-like object named arguments that holds every argument passed. It is not a real array, so it has no map or filter. Arrow functions do not have their own arguments object.
In modern code, prefer rest parameters. They are real arrays, they work in arrow functions, and they show your intent in the signature.
JavaScript always passes arguments by value, but the value of an object variable is a reference. Changing a primitive parameter never affects the caller. Changing a property of an object parameter does.
Reassigning the parameter itself, as in obj = {}, would not change the caller's variable. Mutating the object it points to does.
In casual talk nobody minds, and many docs use the words loosely. In writing about code, use parameter for the declaration and argument for the call.
Yes. Missing ones become undefined, extra ones are ignored by named parameters. Use rest parameters to read the extras.
By value. For objects, the value is a reference, so mutating the object is visible to the caller, but reassigning the parameter is not.
Not in new code. Use rest parameters instead, which give you a real array and work in arrow functions.
Parameters are the named slots in a function definition, and arguments are the values supplied in a call. JavaScript lets the counts differ, filling gaps with undefined. Use default values for optional inputs and rest parameters for variable-length input, and avoid the legacy arguments object.