What’s the Difference Between Arguments and Parameters in JavaScript?

Learn about what the difference between arguments and parameters is in JavaScript, and whether or not it matters which term you use.

What is a JavaScript argument/parameter?

When you execute functions in JavaScript, you have the option of passing on some information to the function as you call it.

The information you pass is either referred to as an argument or a parameter, and most developers will by and large use the two terms interchangeably.

Example:

function greetings(name) {
	console.log(name)
}

greetings('Anna') 

The 'Anna' part is what gets passed when the greetings() function is called.

So is it an argument or a parameter?

Here’s what Dan Abramov’s says about arguments vs. parameters in JavaScript:

They’re called either “arguments” or “parameters” depending on which side you’re reading (function definition or function call). However, this distinction in terminology is pedantic, and in practice these two terms are used interchangeably.

Source

In other words, there is a difference in terms of when to use either term in sheer communication:

  • Parameter: the thing that gets passed within the function definition.
  • Argument: the thing that gets passed when the function is called.

So in the example above, if we are to use textbook correct terminology:

  • We are passing an argument Anna to the function.
  • The name part inside function greetings(name) is a parameter.

However, using the correct term at the right time won’t make a damn difference when it comes to both running and understanding your code.

Of all the things you could worry about in development, this is not one of them — unless you go to a job interview where they really care about this stuff more than your ability to write good code.


Has this been helpful to you?

You can support my work by sharing this article with others, or perhaps buy me a cup of coffee 😊

Kofi

Share & Discuss on