Woah woah, wait a minute! Aren't parameters and arguments the same thing? They both go in a function, and they both hold the same value. What's the difference?
There is only one major difference between arguments and parameters, and it deals with defining and calling a function. When you DEFINE a function, you supply PARAMETERS. When you CALL a function, you supply ARGUMENTS.
function coolFunction(var1, var2)
-- stuff
end
Since we DEFINED this function, var1 and var2 are PARAMETERS. The parameters are user-defined, and are local to the function.
coolFunction(myVar1, myVar2)
Since we CALLED this function, myVar1 and myVar2 are ARGUMENTS. The arguments may also user-defined, but they are NOT local to the function.
Anything can be an argument. If you call the function and put something inside the parenthesis, it becomes an argument.
Here's another example:
function f1(a)
-- a is a parameter when we DEFINE function f1
print(a)
-- a is now an argument because we CALL function print and put a in the parenthesis
end
f1("Epicsauce")
-- Epicsauce is an argument since we CALL function f1 and put Epicsauce in parenthesis
To sum it up, arguments are passed to the function, where the parameters obtain the VALUES of the arguments. Yes, this is a slight difference, but the terminology is accurate, and you will seem smart when you explain the difference between the two. |