nas5w / javascript-tips-and-tidbits

A continuously-evolving compendium of javascript tips based on common areas of confusion or misunderstanding.
MIT License
1.2k stars 72 forks source link

A slight alteration to Rest Syntax section for better understanding #28

Open Abdul-Sen opened 3 years ago

Abdul-Sen commented 3 years ago

I read through the Rest Syntax section and I felt it was improvement could be made by letting readers know that you can use declared params and rest syntax together. We can either state that ...args has to be the last function argument in text or update the example to the following (or do both 🙂):

function myFunc(param1, ...args) {
    console.log(param1 + args[0] + args[1]);
}

myFunc("The Result is: " , 1, 2, 3, 4);
// The Result is: 3

I'd be happy to make the pull request.