Parameters ? Arguments ? Were they ever different ?
July 01, 2020
Confused ?
Well!
I had the same confusion until yesterday ;)
I have seen the two terms being used interchangeably widely throughout the internet.
So, How Do They Differ ?
Simply, parameters are the variables in the function definition, whereas, the arguments are the data passed in the function call statement.
Have you ever heard about the terms formal parameters and actual parameters ?
Good!
Formal parameters are the ones that appear in the function definition.
Whereas,
The actual parameters are the ones that are passed in the function call statement.
So,
To conclude :-
Formal parameters are parameters.
And
Actual parameters are arguments.
Let’s now quickly recap what we’ve learnt via an example :
let payCompliment = function(name, gender) {
if (gender === "male") {
console.log(`Hey ${name}! You look really handsome.`)
} else {
console.log(`Hey ${name}! You look really beautiful.`)
}
}
payCompliment("Pranav", "male")
payCompliment("Meghna", "female")
// Output:
// Hey Pranav! You look really handsome.
// Hey Meghna! You look really beautiful.
Did you notice how we used parameters based on the arguments passed ?
We get data-specific outputs. ie, if you passed “male” for gender, you would be complimented for being handsome. Otherwise, you’d be as beautiful as ever ;)
So,
Yes!
Parameters are a kind of pre-defined structure for the arguments.
Hope you have a clearer picture now regarding the two terms.
Somthing like this :-