All topics
Functionsbeginner

The arguments Object and Rest Parameters

The array-like arguments object available in regular functions, and the modern rest parameter syntax that replaces most of its use cases.

Before ES6 gave us rest parameters, the only way to access all arguments passed to a function — including ones beyond the named parameters — was the arguments object, an implicit array-like value automatically available inside every regular (non-arrow) function. Interviewers ask about this pairing to see whether you know the modern replacement and why it's generally preferred.

`arguments` is like a duffel bag stuffed with everything you brought on a trip, technically holding your stuff but not built with the same compartments and pockets (array methods) real luggage (a proper Array) has. Rest parameters are that proper suitcase — same contents, but organized and ready to use immediately.

Key Concepts

1
arguments behaves somewhat like an array — it has a .length and can be indexed with arguments[0], arguments[1], etc. — but it is not a real array: it lacks methods like .map(), .filter(), or .reduce() directly, and converting it into a real array historically required a trick like Array.prototype.slice.call(arguments). It also only reflects arguments actually passed at the call site, disconnected from the function's declared named parameters in occasionally surprising ways in older non-strict code.
arguments.lengtharguments[0]arguments[1].map()
2
Rest parameters (function sum(...nums) {}) solve the same underlying problem — accessing a variable number of arguments — but produce a genuine Array instance, so all array methods work on it immediately without any conversion step. Rest parameters can also be combined with named parameters, collecting only the 'rest' of the arguments after the named ones (function log(prefix, ...messages) {}), something arguments cannot express since it always contains everything.
function sum(...nums) {}Arrayfunction log(prefix, ...messages) {}arguments
3
Arrow functions don't have their own arguments object at all — referencing arguments inside one looks it up in the nearest enclosing regular function, which is often not what you want — so rest parameters are the only reliable way to collect variadic arguments inside an arrow function. Between the two, modern code almost always reaches for rest parameters, keeping arguments mostly as a piece of legacy knowledge useful for reading older code.
arguments