What Is The Difference Between Parameter And Argument? π€
2020 Jun 17th
Many developers, myself included, use the words “parameter” and “argument” interchangeably. However, their meanings are not the same. In this article, I explain the subtle difference between these two terms.
Therefore, let us clarify what each of these terms means.
PARAMETERS
The parameters refer to the variables that are in the method/function definition. These variables, which we call parameters, receive a value when we call the function or the method. We can think of them as placeholders. In other words, they tell us what values we need to pass to the function/method.
However, an example helps us understand this term better.
function sayHello(name) { console.log(`Hello ${name}!`); }
In the above function, the “name” variable is the parameter. The “name” parameter gets assigned a value when we call the function sayHello
.
ARGUMENTS
The term “arguments” refers to the actual value we pass to the function when we call it. When we call the function sayHello
with the value “Catalin Pit”, the value is the argument.
function sayHello(name) { console.log(`Hello ${name}!`); } sayHello("Catalin Pit");
In the above example, “Catalin Pit” is the argument. In other words, the parameters are the placeholders for where the arguments (values) go.
CONCLUSION
I hope you understand now what is the difference between these two terms.
To sum up, the parameters are in the method/function definition, and they are placeholders for the actual values we pass when calling the method/function. On the other hand, arguments are the actual values that we pass when we call the function/method.
By the way, if you like my articles, consider subscribing to my newsletter!
OTHER ARTICLES OF MINE
- Colorize Your Console.Log() π³π€―
- ES2020 β My Favourite Features From ES2020
- How To Approach Programming As A Code Newbie π€
- How To Get Programming Project Ideas π€
- Increase Your Chances Of Getting Hired As A Code Newbie π‘π
- How To Make Working In Tech Easier? π΄π»
- Shorter If Statements With Ternary Operator π₯π
- Making Promises Better With Async/Await π₯β
- Catalinβs Journey To Software Development π¨βπ»β³
- Impostor Syndrome – A Developer’s Best Friend
- 2 Weeks Of Remote Working π¨βπ»π