What's the difference between argument and parameter in JavaScript

Ask a question+

I’m confused about the two terms Argument and Parameter in a function can anyone explain this to me?

slamsal 10
add comment

1 Answer


Heya slamsal!

When you make a function you have the possibility to give it parameters. These are created when you make the function and are variables that you can use inside of the function. See below

function testFunction(parameterA, parameterB) {
    answer = parameterA - parameterB;

We now want to run the function, lets say someone entered values into textboxes to get the an answer. So someone enters 10 - 5.

let value1 = 10;
let value2 = 5;

We made those into variables and now we want to run the function to get the answer in the console. We need to call the function and put in the value’s in the spaces corresponding to the parameters when we made the function.
So we want that value1 equals parameterA and value2 equals parameterB.

We will now call the function and put the arguments in there!

testFunction(value1, value2);

When we run that, the answer variable will be 5.

In conclusion, we made a function and wanted to use variables in them that we gave to the function, so we added parameters.
We then called the functions and filled it with arguments, those arguments will fill the parameters.

I hope this helps, I’m not the best at explaining things :)

CB_S 20

Okay thanks . I clearly understood what you wrote

add comment

Your Answer