Skip to content

JavaScript Arguments vs Parameters | Difference

  • by

The simple between JavaScript Arguments vs Parameters is arguments are the actual values and parameters are the aliases for the values that will be passed to the function.

// a, b, and c are the parameters
var foo = function( a, b, c ) {};

// 1, 2, and 3 are the arguments
foo( 1, 2, 3 ); 

Parameters are variables listed as a part of the function definition. Arguments are values passed to the function when it is invoked.

JavaScript arguments vs parameters

Simple example code.

<!DOCTYPE html>
<html>
<body>
  <script>
      function fun(x) //x is the parameter 
       { 
        console.log(x);
        console.log("Arguments vs Parameters"); 
      } 

    fun(500); //5 is the argument to the function 
  </script>
</body>
</html>

Output:

JavaScript arguments vs parameters

Here’s a tabular representation of JavaScript arguments and parameters:

AspectParametersArguments
DefinitionVariables listed in the function signatureValues passed to a function during a call
LocationDefined in the function declarationPassed when calling the function
PurposeRepresent placeholders for incoming valuesActual values supplied during invocation
Example Functionjavascript function addNumbers(a, b) { /*...*/ }javascript addNumbers(5, 3);
FlexibilityMust match the function’s parameter listCan be more or fewer than the parameters
Handling ExtrasUnused arguments are ignoredMissing arguments become undefined

This table summarizes the key differences between parameters and arguments in JavaScript.

Do comment if you have any doubts or suggestions on this Js arguments and parameters topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading