function args() { return arguments; }
args();
the reault is ?what’s the "return arguments; meaning?
function args() { return arguments; }
args();
the reault is ?what’s the "return arguments; meaning?
‘arguments’ holds an array of the arguments given. Any number of arguments can be passed.
So for example, assuming the above function:
args(1, 2, 3);
would return an array containing the items 1, 2 and 3.
Say you have a function:
function countArguments(){
return arguments.length;
}
Then:
alert(countArguments("Hello", "World", "3.14159265358979323846", "Hello again"));
Would output 4, because 4 arguments are passed to it.
The function args and countArguments wouldn’t have any real-life use, but I suppose its a theory thing. Realistically a function would use the arguments variable in someway, rather than returning it.