DEV Community

Discussion on: Understanding Rest Parameter Syntax

georgecoldham profile image
George • Edited on

Out of curiosity, why are you choosing to use

function(...[arg1, arg2, arg3]) { //... }


function({ arg1, arg2, arg3 }) { //... }


Is there any technical differences or is this just syntactical preference?

laurieontech profile image
Laurie Author

The first example is using the rest parameter, which is what the article is meant to explain.

The second example would not apply for the example above since it's only passing integers. It would work if the example looked like this though.

function testRest({ first }) {
testRest({ first: 1 });

However, the "infinite" number of arguments use case is not handled unless the arguments in question are already in an object and their key names are known. It's a very different piece of syntax.