DEV Community

KelliLil
KelliLil

Posted on

Difference Between Arguments and Parameters

Both arguments and parameters both use parentheses in syntax in Javascript. While similar, they represent different purposes.

Image description

Above we have a function. This function's assignment is to filter through all the movies in the database (since we are calling a filter it is important that 'movies' is an array) and include a search parameter to look for a particular string.

Image description

Zooming in on this function, these are the parameters of the function. The words can be anything but it's best to make sure that make sense to what you want your function to do.

Parameters are essentially passed to functions by value — so if the code within the body of a function assigns a completely new value to a parameter that was passed to the function, the change is not reflected globally or in the code which called that function.
source: MDN

Alternatively, when you go to call this function, you will need to pass through the arguments. Below is the code to check and make sure that the function we wrote is actually working.

Image description

The parameters have changed, slightly in the arguments. 'movies' in the argument has nothing to do with 'movies' in the parameter of the function. I could have easily name the arguments (myMovies,"The"). As long as the first argument is an array like how the parameters are set in the function is what matters.

Image description

Instead of using search like we wrote in the parameters of the function, we turned that object into the string "The" as an argument. What we are passing through in the arguments is to filter through all of the movies in the database and bring us the ones that have "The" somewhere in the title.

When that function is run, it would look like this: The function we created went through the array of movies in my database then filtered through the films and called the information we passed through the arguments.

Image description

Top comments (0)