Function parameters versus function arguments
Learn about the difference between parameters and arguments for functions when programming.
1 min read
When speaking about functions in programming, it is common to confuse the terms parameters
and arguments
. What does each term refer to and which one should you use? Let's find out.
- Function parameters are the names that are listed in a function's definition.
- Function arguments are the real values that get passed to the function.
Parameters are initialized to the values of the arguments supplied to the function. Parameter variables are used to import arguments into functions.
Parameters versus arguments
Let's use JavaScript to create a simple example that will help us to better understand the difference between parameters and arguments.
function divide(numerator, denominator) {
return denominator > 0 ? numerator / denominator : 0;
}
console.log(divide(10, 5)); // 2
The parameters of this function are numerator
and denominator
seen in the function definition of function divide(numerator, denominator)
. The arguments are the values of 10
and 5
that get passed to the function in the function call of divide(10, 5)
.