DEV Community 👩‍💻👨‍💻

Cover image for What are parameters and arguments?
Aweys Ahmed
Aweys Ahmed

Posted on • Updated on

What are parameters and arguments?

You'll definitely hear the words parameter and argument during your coding journey. In some cases, you may hear them being used interchangeably, however, they are different but closely related.

Let's use an example to get a better understanding of parameter and argument.

When you are declaring a function, you will state the parameters required for it to work.

def multiply(x, y)
  x * y
end

# x and y are the parameters
Enter fullscreen mode Exit fullscreen mode

In the above example, we created a function that has two parameters, x and y. A parameter is what is required to make the function work when it is declared

An argument is what is actually passed to the function when it is being called.

multiply(2,3)

# 2 and 3 are the arguments
# output 6 
Enter fullscreen mode Exit fullscreen mode

When we use a function and pass in data, then it is called an argument. So we passed two arguments to the multiply function.

I hope this helps clarify the use of these two terms.

Top comments (2)

Collapse
 
ljbarnes profile image
Leah Barnes

Helpful and explained clearly--thanks!

Collapse
 
aweysahmed profile image
Aweys Ahmed

Thank you for the kind feedback. :)

Advice For Junior Developers

>> Check out this classic DEV post <<