Glossary / arguments
arguments
arguments is an array-like object available inside traditional function code that contains the arguments supplied to that invocation. It has indexed properties and a length, but it is not an Array and does not provide the full Array prototype. Arrow functions do not create their own arguments; they may resolve an outer binding instead.
Mapped and unmapped behavior
In non-strict ordinary functions with simple parameter lists, named parameters and corresponding arguments indices can be linked:
function sloppy(value) {
value = 9;
return arguments[0];
}
Strict functions use an unmapped arguments object, so changing value does not change arguments[0], and changing the index does not update the parameter. Modern non-simple parameter lists also do not use mapped arguments. This aliasing was a legacy convenience but makes behavior difficult to analyze.
function inspect(value) {
"use strict";
value = 9;
return [value, arguments[0]];
}
inspect(2); // [9, 2]
Use a rest parameter when a function intentionally accepts variable arity: function log(first, ...rest) {}. Rest is a real Array, works in arrow functions, and states the API contract clearly. arguments.callee is deprecated/forbidden in strict code; use a named function for recursion. Avoid reading beyond declared parameters unless the function deliberately documents a variadic signature.
Interview questions
- Is
argumentsan Array? No; it is array-like. Convert withArray.fromor use rest parameters. - Do arrows have their own
arguments? No. - What is mapped arguments behavior? In certain sloppy functions, indexed argument values alias named parameters.
- What is the modern alternative? Rest parameters, which create a true array.
- Why avoid
arguments.callee? It is restricted in strict mode and interferes with optimization and clear recursion structure.