I was looking at a javascript library and noticed that you can access arguments passed to a function using an arguments array like so...
function foo() {
var firstArg = arguments[0];
var secondArg = arguments[1];
//code
}
I had always done this by specifying parameters right in the function definition
function foo(firstArg, secondArg) {
//code
}
What are the advantages/disadvantages of these two strategies for reading function arguments?
argumentsgives the flexibility ofnnumber of args, & the other one is for fixed number of args.argumentsonly for variadic functions. Functions with fixed arity should use named parameters (and this is also available asfoo.length)