When talking about code, arguments and parameters are oftentimes mixed up. So let's clarify that once and for all!
Let's have a look at a simple JavaScript function:
function log(a, b) {
// do something
}
const myString = "codesnacks"
log(10, myString)
So we have a log
function, that takes two parameters, a
and b
. And we're calling it with the two arguments 10
and myString
.
The parameters a
and b
are potential values, 10
and myString
, the arguments, are actual values.
It's relatively easy to remember if you keep the following in mind:
Parameters are Placeholders.
Arguments are Actual values.
Top comments (6)
I did not know this! I thought they were synonyms for each other.
That is a really nifty mnemonic for a difference I was not quite clear on yet. Thank you!
This is great!
I knew which is which, but a mnemonic is super handy!
There are some languages that offer Pass By Value and Pass by Reference
most programming languages are Pass By Value
Thanks buddy
I never thought about this. Thanks :)