You can pass any number of arguments to a function, of any type. The function could determine for itself what they are and whether they are suitable, though that is not usually necessary: you decide what parameters should be used with a particular function when you write it. Parameter names and comments should show what is intended.
Every function has a read-only property called arguments
which is an object of type Arguments
. It is used as an array: the ith parameter passed to the function is arguments [i]
and the number of parameters is arguments.length
.
Parameter type can be determined with the typeof
operator (a couple of pages back).
Also check for missing arguments with
if (typeof arg == "undefined")
...
The idea that you do not have to specify how many parameters a function may take is exploited in some JavaScript libraries (eg, jQuery).