From the course: Learning the JavaScript Language

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

Three little dots collect the rest

Three little dots collect the rest - JavaScript Tutorial

From the course: Learning the JavaScript Language

Three little dots collect the rest

- [Instructor] In our efforts to become conversant in JavaScript, there's a bit of newer syntax that we might see that's going to appear a little bit mysterious. It looks like an ellipses, but it's actually three dots typed as three periods or full stops in the parenthesis of a functions declaration. This is called rest parameters, and the result is an array of arguments. Previously, we've seen the array like object called arguments but this is an actual JavaScript array. So along with the length property it has all the methods that regular arrays have for sorting and otherwise manipulating the items. That might not be something you'll put into use very often but it's good to know. Here's the adding machine function we saw previously rewritten to use rest parameters. Because it's the only parameter in the function, all arguments are captured in terms here and can be looped over just like we did previously with the…

Contents