In the same way that method parameters can be assigned multiple values, arguments
used in concert with a function may also be assigned multiple values when the function is invoked.
This special variable is called an argument. The argument variable is only declared, not initialized,
in a function's parenthesis. It is initialized when the function is called just by including a value with the function call.
Since the same function can be called multiple times, the value assigned can be different for each call. Assigning values to argument variables in this way is known as passing arguments.
There are three steps involved in using arguments:
Declare the argument in the function's parentheses.
Within the function, include the argument in the location it will be used.
Assign the value of the argument when the function is called.
function favoriteNumber(myArg) {// 1. declare
alert(myArg) // 2. used here
}
<input type="button" onclick="favoriteNumber('One')"> <!-- 3. assign value -->
<input type="button" onclick="favoriteNumber('Two')"> <!-- 3. assign value -->
In the above example, the value of myArg is "One" when the first call to the function is made. When the second call to the function is made, the value of myArg is "Two". If I didn't use an argument here, there would have to have been 2 functions written for each value.
Multiple Arguments
Multiple arguments can be used within the same function, just separate the arguments with commas when they are declared and when they are assigned a value.
function passStuff(myArg1,myArg2,myArg3) {
alert(myArg1 + myArg2 + myArg3)
}