And another function with a variable calling the myFunction
function anotherFunction {
var myVar = "Something";
myFunction(myVar);
}
Now updating the first function below, it would seem that I can use virtually any word to get the same data. What is the thought behind this? Are we just supposed to keep track and keep everything in sequential order when you have more than one parameter or argument being sent to a function?
function myFunction(WhateverWordCanGoHere) {
// some code
alert(WhateverWordCanGoHere);
}
As you can see the variable myVar is being referenced as WhateverWordCanGoHere. This doesn’t seem to make much sense.
If you add pass another variable to the function myFunction, then whatever the second word is works.
Can someone explain this logic? It just seems that the word doesn’t matter but the amount of comma-separated words and their sequential order do.
The benefit of function parameter names is that it doesn’t matter which variable name is used when calling the function. The benefit being that regardless of what’s happening outside, it’s always the same parameter name on the inside of the function that’s used.
You can have several different variable names, and use all of them to call a function.