Understanding the Difference Between Parameter and Argument
Published: 2023-11-13 05:11:52

I know that a lot of people have probably done this topic before me, but for the longest time it still didn't click. And I see others struggle with this all the time. So, I thought that perhaps I'd try to explain it in the way that made sense to me.


So what is the confusion about? Well, the confusion lies 
in the fact that Parameters frequently get called Arguments! But they are not the same thing. So, what is the difference? Lets define them!

**What is a Parameter?**
Parameters are a part of your Function! They are the words that go inside your function's parenthesis( )! They are the **names** listed in the functions definition.

Function Declaration ex:

![function declaration](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/av8me0t8j4t4xqsobkir.png)

Function Expression ex:

![function expression](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lhljvw3rcqrl0mdycthi.png)

Some functions call for multiple parameters that are separated by comma's.

Example:

![multi-parameter function](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xdfioj5ilb86vljcqy47.png)

Here are some things to keep in mind about Parameters:

- parameters don't specify data type
- parameters can be undefined
- parameters can hold a default value
  
ex: 

![default value declared](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f36877hjhku54ozcz3jj.png)

   - this way, if b is not passed in the argument 
    or is undefined, b will equal 2 

   ex: 

![answer to above](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l216qa2bsonfu3ab9fl3.png)

Most Important to remember:
A parameter is a **placeholder** and has no real value! A parameter can be named anything. It is recommended, however, that when you name a parameter, you give it a name that refers to the information it will be taking in.



**What is an Argument?**
Arguments in this discussion are a value used to help invoke the function. It also goes inside the parenthesis ( ). There is a lot more to arguments, but right now I'm focusing on how it compares to the parameter.

Example:

![Arg vs Param](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ty92tfavr0bx1g5wm5wu.png)

Unlike the parameter, the argument receives an actual value. We then pass the assigned value of the argument into the parameter's variable placeholder.
Some extra things about arguments
- arguments are data types
   - they can be a string, a boolean, a number
- arguments can also be variables

![variable arguments](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1r9c5aontq53i5y48mzd.png)
- arguments can also take expressions

![argument expression](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qvo6jd9gen1yml4jpamu.png)

Last note:
- A parameter is only defined once, at the time of function declaration. 
- An argument may be defined multiple times, meaning it may change each time the function is called.

I hope this helped for some more people, who like me struggled to make sense of the difference between parameters and arguments. 
 
To leave you: 

![animalGreeting](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ozcrzgqav706x2j9wglz.png)


![Tedward](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/19jgfb9rsvwqgdj8v36e.png)


| |

![Tequila](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eta6lrfiuw6vmwu9mqrp.png)


![Tequila the Chihuahua](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p232wg11j5humgzwg3ax.png)







Sources:
Freeman, Eric, and Elisabeth Robson. _Head First JavaScript Programming: A Brain Friendly Guide._ O'Reilly, 2014.
'JavaScript FunctionParameters.'_W3Schools.com_, Retrieved 9 November 2023 from (https://www.w3schools.com/js/js_function_parameters.asp)
Mustafeez, A. Z.'Parameter vs. argument'. educative.io. Retrieved 9 November 2023 from (https://www.educative.io/answers/parameter-vs-argument)