arguments
is actually an object, not an array
. When you print it out, you will see that it resembles an object:
function bar (x,y) {
console.log(arguments);
}
bar(30,40);
Output: { '0': 30, '1': 40 }
According to the information on this documentation,
This object has a specific entry for each argument passed into the
function, starting with an index of 0. For example, if three arguments are passed into a function, they can be accessed like this:
arguments[0] arguments[1] arguments[2]
The object doesn't possess any properties commonly found in arrays except for length
.
Therefore, trying to execute return arguments.slice(0);
would result in an error because slice
is associated with the prototype
of an array
.