DEV Community

Cover image for Arguments vs Parameters in JavaScript
Oluwatobi Sofela
Oluwatobi Sofela

Posted on • Originally published at codesweetly.com

Arguments vs Parameters in JavaScript

People often use arguments and parameters interchangeably, but they are different. So, let's discuss their differences.

What Is the Difference between Arguments and Parameters?

Arguments are the optional values you pass to a function through an invocator. And parameters are the names you assign to the values.

Arguments vs. parameters anatomy

Arguments are values. Parameters are the names of the values.

Syntax of Arguments vs. Parameters

We specify parameters and arguments in the parentheses that follow your function's name. Here's the syntax:

function nameOfFunction(parameter1, parameter2) {
  // function's body
}

nameOfFunction(argument1, argument2);
Enter fullscreen mode Exit fullscreen mode

Example of Arguments vs. Parameters

// Define a function with two parameters:
function bestColors(first, second) {
  return first + " " + second;
}

// Invoke the bestColors() function with two arguments:
bestColors("White", "Blue");

// The invocation above will return: "White Blue"
Enter fullscreen mode Exit fullscreen mode

In the snippet above, "White" and "Blue" are the arguments (values) we passed to the function's first and second parameters.

Important Stuff to Know about Arguments and Parameters

Here are two essential facts to remember when using JavaScript arguments and parameters.

1. Arguments and parameters are optional

Arguments and parameters are optional components of a function. In other words, you can omit the parameters if your function won't use any argument.

For instance, JavaScript's trim() method has no parameter because it takes no arguments.

On the other hand, match() has a single parameter that accepts one argument.

2. Arguments vs. arguments object

JavaScript automatically adds an array-like object (called arguments) to every non-arrow function you define.

The arguments object stores all the arguments (values) you pass to your function's parameter.

In other words, JavaScript will put each value (argument) you pass to your function's parameter into the function's built-in arguments object.

Here's an example:

// Define a function with two parameters:
function bestColors(first, second) {
  return arguments;
}

// Invoke the bestColors() function with two arguments:
bestColors("White", "Blue");

// The invocation above will return:
["White", "Blue"]

// Note: Some browser's returned value may look like so:
{0: "White", 1: "Blue"}
Enter fullscreen mode Exit fullscreen mode

bestColors() returned an array-like object having the values we passed to its parameters because we programmed it to return its built-in arguments object's content.

Overview

Arguments are the values users pass to a function's parameters.

Thanks for reading

I hope you've found this article helpful. Please, feel free to reach out if you have any questions.

You can also visit my website for more articles like this.

Want to connect? Follow me on Twitter.

Quadratic AI

Quadratic AI – The Spreadsheet with AI, Code, and Connections

  • AI-Powered Insights: Ask questions in plain English and get instant visualizations
  • Multi-Language Support: Seamlessly switch between Python, SQL, and JavaScript in one workspace
  • Zero Setup Required: Connect to databases or drag-and-drop files straight from your browser
  • Live Collaboration: Work together in real-time, no matter where your team is located
  • Beyond Formulas: Tackle complex analysis that traditional spreadsheets can't handle

Get started for free.

Watch The Demo 📊✨

Top comments (0)

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, cherished by the supportive DEV Community. Coders of every background are encouraged to bring their perspectives and bolster our collective wisdom.

A sincere “thank you” often brightens someone’s day—share yours in the comments below!

On DEV, the act of sharing knowledge eases our journey and forges stronger community ties. Found value in this? A quick thank-you to the author can make a world of difference.

Okay