Sitemap
We’ve moved to freeCodeCamp.org/news

We’ve moved to https://freecodecamp.org/news and publish tons of tutorials each week. See you there.

How JavaScript rest parameters actually work

3 min readDec 20, 2017

--

Zoom image will be displayed

My last article covered spread syntax and Object.assign in detail, but glossed over rest parameters in the interest of time. I do, however, feel they deserve a closer look.

Let’s begin at the trusty MDN Docs:

The rest parameter syntax allows us to represent an indefinite number of arguments as an array.

That last part, “as an array”, is interesting, because before ES6 arrow functions, we used the arguments object. It was array-like, but not actually an array.

Example:

function returnArgs() {
return arguments;
}
Zoom image will be displayed

We see arguments has indices, so it’s loop-able:

function loopThruArgs() {
let i = 0;
for (i; i < arguments.length; i++) {
console.log(arguments[i]);
}
}
Zoom image will be displayed

But it’s not an array.

--

--

No responses yet