Parameter
Parameters are named variables declared as part of afunction. They are used to reference thearguments passed into the function.
For example:
js
const argument1 = "Web";const argument2 = "Development";example(argument1, argument2); // passing two arguments// This function takes two valuesfunction example(parameter1, parameter2) { console.log(parameter1); // Output = "Web" console.log(parameter2); // Output = "Development"}There are two kinds of parameters:
- input parameters
the most common kind; they pass values into functions. Depending on the programming language, input parameters can be passed in several ways (e.g., call-by-value, call-by-address, call-by-reference).
- output/return parameters
primarily return multiple values from a function, but are not recommended since they cause confusion
In this article
Parameters versus arguments
Note the difference betweenparameters andarguments:
- Function parameters are the names listed in the function's definition.
- Functionarguments are the real values passed to the function.
- Parameters are initialized to the values of the arguments supplied.