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:
Here’s a tabular representation of JavaScript arguments and parameters:
Aspect | Parameters | Arguments |
---|---|---|
Definition | Variables listed in the function signature | Values passed to a function during a call |
Location | Defined in the function declaration | Passed when calling the function |
Purpose | Represent placeholders for incoming values | Actual values supplied during invocation |
Example Function | javascript function addNumbers(a, b) { /*...*/ } | javascript addNumbers(5, 3); |
Flexibility | Must match the function’s parameter list | Can be more or fewer than the parameters |
Handling Extras | Unused arguments are ignored | Missing 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