Skip to content Skip to sidebar Skip to footer

How Does The Spread Syntax In Es6 Js Work As A Function Argument?

OK, so I'm trying to understand how the new spread works as a function parameter. Imagine a function with an unknown number of parameters and adds them all together. let addNums =

Solution 1:

After doing more research, I was able to find a reference to what are called rest parameters.

Rest parameters look like they use the ... spread syntax as part of the parameter, but behave differently. They will in fact collect an indefinite number of arguments/parameters and then make them available as an array inside the function.

Source: link to MDN description of 'rest' parameters

Basically the behaviour that I observed in the first place!

Post a Comment for "How Does The Spread Syntax In Es6 Js Work As A Function Argument?"