What's the Difference between a Parameter and Argument?

Eugene Yeboah

Written by:

Eugene Yeboah • January 3, 2022

What's the Difference between a Parameter and Argument?



Parameters and Arguments are often confused in the world of software development, it's understandable because the concepts are very closely tied which results in the terms often being used incorrectly. With that said, there is a clear distinction. In this post, we'll understand the difference between Parameters and Arguments by explaining the concept using analogies that we see in everyday life. Let's start off by defining these terminologies and building on these definitions.

Simple Definitions: Parameter vs Argument?

[code language="javascript"] function greeting (name) { return console.log('hello ' + name); } greeting('Eugene'); greeting('Michael'); [/code] Output (result of running the above code): [code] hello Eugene hello Michael [/code] In the above code we have a function by the name of greeting - line 1. This function has a 'name' parameter. The function: greeting prints out 'hello ' + value of name. So now the question is, what is the value of name? Well, the name value is set when we call the function. We call the function on line 4 (and 5): greeting('Eugene');. Notice that when we call the function, we pass in a string ('Eugene'). This string is the argument that we are passing into the greeting function. The output section is the result of calling the function, twice in this case. The first call is on line 4 with ('Eugene') as an argument, the second call is on line 5 with ('Michael') as an argument. Notice that I wrote the function once, but can call it as many times as I want (line 4 and 5 as an example). Questions you may be asking:

Summarizing with an everyday analogy: Your Car and the gas you put into it! I don't fully understand what makes a car run, but I do know that when I get in my car and turn the key, it starts and I'm able to drive. We know that a car takes in gas in order to operate (or electricity). With that said, obviously you can't just pour anything into your car and expect it to run. If you pour in milk, or juice, you car will not work. Not only do you have to pour in gas, you have to use a certain type of gas that will work with your vehicle. How does this relate to functions, arguments, and parameters?

That's all - Questions? Leave them in the comment section below.