February 2019
Beginner
694 pages
18h 4m
English
The JavaScript language also allows a function to be called with a variable number of arguments. To illustrate this point, we can make use of a quirk of the JavaScript language. Every JavaScript function has access to a special variable, named arguments, that can be used to retrieve all arguments that have been passed into the function. As an example of this, consider the following JavaScript code:
function testArguments() {
if (arguments.length > 0) {
for (var i = 0; i < arguments.length; i++ ) {
console.log("argument[" + i + "] = " + arguments[i]);
}
}
}
testArguments(1,2,3);
testArguments("firstArg");
Here, we have defined a function, named testArguments, which does not have any named parameters. Note, though, that we can ...
Read now
Unlock full access