Most programmers use these terms without distinction of meaning. In practice, saying the word wrong or right will not make the code work or not, it will depend on you, but it is always good to know and understand the differences.
Imagine a parameter like a variable that can be received by a function or a method. To better understand see this example in Javascript:
function somar(param1, param2) {
return param1 + param2;
};
This function will always receive two parameters (param1 and param2). Moreover, its output will always depend on the input. Therefore, with this small explanation we can already conclude that the parameter will always be linked to your input.
The rules for how parameters are passed to functions are determined by the programming language, for example, these rules can specify the order of parameters, whether they are passed from left to right, or the other way around. Moreover the rules can define whether the parameters will be passed by reference or value.
Note: The parameters can be of any type, an array, an integer, a String, or other type of data (of course this varies in the programming languages).
On the other hand we have the argument, which would be the value passed (may be more than one) the function at the time of its call. See:
let valor1 = 10;
let valor2 = 20;
let valorSoma = somar(valor1, valor2);
During the execution of the above code, the variables "valor1" and "valor2" are initialized and passed as arguments for the function somar()
. Within it, the parameters are evaluated and the arguments '10' and '20' are obtained. These values are summed, the result is returned and assigned to the variable "valueSoma ". It is important to note that variables are neither parameters nor arguments.
I believe that only with the explanation above is it possible to understand the logic and difference parameters and arguments, but let’s see in simpler ways what each can mean.
I have heard definitions (and they are still true) that an argument could be the parameter instance, not literally, but it is an interesting analogy.
Another way to identify (not to forget) the difference of each:
References:
Big question, always have the same doubt. No more :)
– brasofilo
The parameter is the requirement that the enterprise function for the value to be passed as argument (which may be valid or not) :)
– Wallace Maxters