Parameters are variables used to receive and store the data that a function needs in order to work.
Arguments, on the other hand, are the actual values passed into a function when it is called.
Parameters = placeholders / receivers
They are variables that wait to receive values.Arguments = actual values / real data
They are the values you pass in when calling a function.
Easy way to remember
function returnParameter(p) {
return p; // p is a parameter (a placeholder)
}
returnParameter('Argzzz'); // 'Argzzz' is an argument (the actual value)
Question
Are x and y parameters or arguments in the function below?
function findAverage(x, y) {
let avg = (x + y) / 2;
return avg;
}
console.log(findAverage(11, 7));
Answer
xandyare parameters because they are defined in the function declaration.
11and7are arguments because they are the values passed into the function when it is invoked.
Quick Summary
Parameters → placeholders / variables (empty boxes 📦)
Variables listed in the function definition (x,y,p)Arguments → real values (what you put in the boxes 🎁)
Actual values passed when calling the function (11,7,'Argzzz')
Credits: Udacity
Top comments (0)