travis.media

The Difference Between a Parameter and an Argument

Is there a difference between a parameter and an argument? Are they synonymous with one another?

I've been guilty of it myself when talking about functions……using the words parameter and argument interchangeably.

I mean, they both come after the function name in the parentheses right?

Right!

Then what's the difference between a parameter and an argument?

Our Example

Let me explain in this very simple function:

function squared(number) {
  return number * number;
}

Parameter Explained

The parameter of this function is number.

This is the variable name used to reference the arguments passed to the function.

It can be named anything, but you should choose something relevant.

Argument Explained

The argument of this function will be what you actually pass to it.

When we call this function we will pass a real number as an argument like this:

squared(4);

The argument is 4 and the function will return 16.

If we passed 5 as the argument, the function will return 16.

Conclusion

As you see, this is a subtle but important difference in terms.

Our function has number as the parameter used to reference the argument we will pass to the function (4 or 5 as our examples above).

Hope this helps next time we use the two terms.

Have you mixed these two up before? I think we all have!!

 

----------

** This article may contain affiliate links. Please read the affiliate disclaimer for more details.

About Me Author

Travis of

Travis Media

Who Am I? I was 34 years old in a job I hated when I decided to learn to code. Read More
Explore

You May Also Like