Parameters and Arguments in JavaScript

Natalia Wit
2 min readNov 9, 2020

I remember when I started learning Javascript for the first time and I asked someone what is the difference between an argument and parameter in JavaScript and their answer was honestly I have no idea — that's a great question. This is why I am writing this blog to make it clear about the difference between both. I feel as the parameter and argument terms are mentioned as if they were the same thing but in programming reality, they are really not.

Parameters are slots/placeholders for inputs that a function will receive and arguments are data that are passed into the slots when we run/invoke the function.

I will make this more clear with some code snippets below.

One thing that's important to mention here is that JavaScript does not throw an error during function invocation when the number of arguments is different from the number of parameters listed when we define a function. In the above code snippet above you can see that we defined an addNums function with two parameters and inside we are logging both of them by adding them together. In line 7 we are invoking the function with four arguments, the function will grab the first two by order and ignore the other two without throwing any errors. In line 12 we are invoking a function with one argument which will log NaN because it will add 1 + undefined. If an argument is missing it will just automatically set to undefined — note that you will still not get any errors if you test the code in the browser's console.

When you are technically explaining the difference between these two terms, it is very important to know the difference so you can help another person out of confusion. Most people confuse both of these terms to be the same thing when it really isn't — the easiest way to remember it is that parameter is used when we define a function and argument is passed in when we invoke the function.

--

--