Inside a function, `arguments` exposes the values passed to that invocation—even when more values are passed than the function declares parameters. It resembles an array, but it is not an array, so array methods such as `sort` are unavailable. section 4.1.1
Use it with care:
- `arguments.length` gives the total number of values passed, and indexed access can retrieve extra arguments that have no matching named parameter. section 4.1.1
- In nonstrict mode, indexed values alias the corresponding named parameters: changing one changes the other. Strict mode prevents that aliasing. section 4.4
- The object can support variadic functions and function-overloading patterns, but rest parameters reduce the need for it. section 4.1.1
Listing 4.1. Using the arguments parameter
function whatever(a, b, c){ #A
assert(a === 1, 'The value of a is 1'); #B
assert(b === 2, 'The value of b is 2'); #B
assert(c === 3, 'The value of c is 3'); #B
assert(arguments.length === 5, #C
'We’ve passed in 5 parameters'); #C
assert(arguments[0] === a, #D
'The first argument is assigned to a'); #D
assert(arguments[1] === b, #D
'The second argument is assigned to b'); #D
assert(arguments[2] === c, #D
'The third argument is assigned to c'); #D
assert(arguments[3] === 4, #E
'We can access the fourth argument'); #E
assert(arguments[4] === 5, #E
'We can access the fifth argument'); #E
}
whatever(1,2,3,4,5); #F
A function declares three parameters but receives five values; the example compares named parameters with `arguments.length` and indexed access to the extra values. section 4.1.1
