DEV Community

AnneMiriam
AnneMiriam

Posted on

Understanding the Difference Between Parameter and Argument

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

Function Expression ex:

function expression

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

Example:

multi-parameter function

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

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

ex:

answer to above

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

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

  • arguments can also take expressions

argument expression

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

Tedward

| |

Tequila

Tequila the Chihuahua

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)

Top comments (0)