Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Functions  ›  Lesson

The arguments Object

arguments object 10 minInside a regular function, arguments is an array-like object holding every value the call actually passed, even ones with no matching named parameter — but arrow functions have no arguments of their own, and modern code usually prefers rest parameters instead.

The arguments Object

In short: inside a regular function, arguments is an automatic, array-like object holding every value the call actually passed — even ones with no matching named parameter. It has a .length and numeric indices, but it isn't a real array (no .map, no .filter directly). Arrow functions have no arguments of their own — they see the arguments of whatever regular function encloses them, if any. Modern code usually prefers rest parameters (...args) instead, which are real arrays.

sum(10, 20, 30, 40) called against function sum(a, b) { ... }: the arguments bag catches all four values, even though only a and b are named parameters; a trap note that arrow functions have no arguments object of their own

Catching every value passed, named or not

arguments doesn't care how many parameters you declared — it holds what was actually sent:

javascript

a and b fill the first two slots, as usual. But arguments isn't limited to named parameters — it has all four values, [10, 20, 30, 40], because that's what the call sent, regardless of what the function signature promised to use.

Summing an unknown number of arguments

Before rest parameters existed, arguments was how you wrote a function that accepts any number of values:

javascript

No parameters are declared at all — total() works purely off arguments, looping through however many values a particular call happens to pass.

Arrow functions silently borrow the wrong arguments

The trap isn't that an arrow function without arguments errors out — it's that it silently reaches outward and picks up whatever arguments happens to be in scope, which is very often not what you meant:

javascript

makeLogger("a") returns an arrow function. That arrow has no arguments of its own, so every time it runs, arguments means makeLogger's — frozen at 1, from the call that created it. Calling logger(1, 2, 3) later doesn't change that: the 1, 2, 3 never reach an arguments object at all, because there isn't one for this call. Rest parameters (...args) fix this properly: args belongs to the arrow itself, built fresh from whatever that specific call passed in.

Reach for ...args in any function — arrow or not — that needs "every value passed in." It's a real array, and it's never borrowed from somewhere else by accident.

Quick practice

quick drill

function f(a, b) { return arguments.length; } called as f(1, 2, 3, 4) — what does it return?

quick drill

Is arguments a real JavaScript array?

quick drill

function makeLogger() { return () => arguments.length; } — what does makeLogger("a")(1, 2, 3) return?

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainMore arguments than parameters

function sum(a, b) { return arguments.length; } called as sum(10, 20, 30, 40) returns 4, not 2. Explain why, and what a and b each hold in that call.