Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

JS Puzzles · Const

arguments object

The arguments object is an array-like, iterable collection of every value supplied to a traditional function. It supports indexes and length, but not Array methods, and arrow functions inherit arguments from an enclosing normal function.

How it works

Inside a traditional function, arguments exposes every value supplied at the call site through numeric indexes and length. It is iterable and array-like, but it is not an Array, so convert it before using array methods. Arrow functions do not create their own arguments object.

Syntax

arguments

Key points

  • A traditional function can inspect every supplied argument through numeric indexes.
  • Use arguments.length to count how many values the caller supplied.
  • The object is iterable, so it can be traversed with for...of.
  • Treat arguments as array-like rather than as a true Array.
  • Convert arguments to an Array before calling Array methods.
  • It includes values even when the function declaration has fewer named parameters.

Common mistakes

  • arguments has indexes and length, but it does not provide Array methods such as map or reduce.
  • Arrow functions do not have their own arguments object; an arguments reference resolves to an enclosing normal function.
  • Unlike rest parameters, arguments cannot capture only a selected portion of the supplied values.

Example: Read all supplied arguments

function total() {
  return Array.from(arguments).reduce((sum, value) => sum + value, 0);
}

console.log(total(2, 3, 5)); // 10

Converts the array-like object to an array, then sums every supplied argument.

When to use it

Variadic functions

Accepting a variable number of values in legacy or interop code.

Argument counting

Inspecting how many values a caller supplied.

Dynamic argument processing

Iterating over caller-supplied values in a traditional function.

  • rest parameters
  • spread syntax
  • Array.from()
  • for...of

Source: Rest parameters and spread syntax. Checked 2026-10-15.