DEV Community

Mohamed Idris
Mohamed Idris

Posted on • Edited on

𝐏𝐚𝐫𝐚𝐦𝐞𝐭𝐞𝐫𝐬 𝐯𝐬. 𝐀𝐫𝐠𝐮𝐦𝐞𝐧𝐭𝐬?

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)
Enter fullscreen mode Exit fullscreen mode

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));
Enter fullscreen mode Exit fullscreen mode

Answer

x and y are parameters because they are defined in the function declaration.
11 and 7 are 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)