freecoding.school100% FREE · NO SIGNUP
Closure CavesISSUE #11 of 61

arguments · the legacy array-like

LambdaVSThe Mutator
Lambda saysThe arguments object is an array-like list of all args in a regular function (legacy; prefer rest).

Inside a non-arrow function, arguments holds every passed value, even unnamed ones. It's array-like (has length/indexing) but not a real array, so methods like map don't work without converting. Modern code uses a rest parameter (...args) instead — it's a real array and clearer.

Power-ups you unlock

The Mutator attacks — common mistakes

Boss battleSum all arguments via the arguments object, then rewrite with a rest parameter.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre id="o"></pre>
<script>function sum(){ return [...arguments].reduce((a,b)=>a+b,0); }
document.getElementById('o').textContent='sum = '+sum(1,2,3,4,5);</script></body></html>
▶ Open the interactive comic issue
‹ Call · Apply · Bind · Changing ThisObjects · Key · Value Pairs ›