Function.prototype.arguments
Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see thecompatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.
Non-standard: This feature is not standardized. We do not recommend using non-standard features in production, as they have limited browser support, and may change or be removed. However, they can be a suitable alternative in specific cases where no standard option exists.
Note:Thearguments
property ofFunction
objects is deprecated. The recommended way to access thearguments
object is to refer to the variablearguments
available within functions.
Thearguments
accessor property ofFunction
instances returns the arguments passed to this function. Forstrict, arrow, async, and generator functions, accessing thearguments
property throws aTypeError
.
Description
The value ofarguments
is an array-like object corresponding to the arguments passed to a function.
In the case of recursion, i.e., if functionf
appears several times on the call stack, the value off.arguments
represents the arguments corresponding to the most recent invocation of the function.
The value of thearguments
property is normallynull
if there is no outstanding invocation of the function in progress (that is, the function has been called but has not yet returned).
Note that the only behavior specified by the ECMAScript specification is thatFunction.prototype
has an initialarguments
accessor that unconditionally throws aTypeError
for anyget
orset
request (known as a "poison pill accessor"), and that implementations are not allowed to change this semantic for any function except non-strict plain functions. The actual behavior of thearguments
property, if it's anything other than throwing an error, is implementation-defined. For example, Chrome defines it as an own data property, while Firefox and Safari extend the initial poison-pillFunction.prototype.arguments
accessor to specially handlethis
values that are non-strict functions.
(function f() { if (Object.hasOwn(f, "arguments")) { console.log( "arguments is an own property with descriptor", Object.getOwnPropertyDescriptor(f, "arguments"), ); } else { console.log( "f doesn't have an own property named arguments. Trying to get f.[[Prototype]].arguments", ); console.log( Object.getOwnPropertyDescriptor( Object.getPrototypeOf(f), "arguments", ).get.call(f), ); }})();// In Chrome:// arguments is an own property with descriptor {value: Arguments(0), writable: false, enumerable: false, configurable: false}// In Firefox:// f doesn't have an own property named arguments. Trying to get f.[[Prototype]].arguments// Arguments { … }
Examples
Using the arguments property
function f(n) { g(n - 1);}function g(n) { console.log(`before: ${g.arguments[0]}`); if (n > 0) { f(n); } console.log(`after: ${g.arguments[0]}`);}f(2);console.log(`returned: ${g.arguments}`);// Logs:// before: 1// before: 0// after: 0// after: 1// returned: null
Specifications
Not part of any standard.