Nice post, John, but sorry for being a bit pedantic -- this is syntax and the idea is best known as "rest parameters" (not to be confused with REST) according to MDN.
One example that often isn't shown that I'd like to share is in the use of recursive operations:
functionheadOperation(arr,operation){if(arr.length===0)return;// base case (empty array) - terminateconst[head,...tail]=arr;operation(head);headOperation(tail);// operate on rest of list (tail)}
Not necessary in JS, but this is very common in functional programming languages where loops constructs don't exist but all recursive calls are TCO (tail-call optimized)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Nice post, John, but sorry for being a bit pedantic -- this is syntax and the idea is best known as "rest parameters" (not to be confused with REST) according to MDN.
One example that often isn't shown that I'd like to share is in the use of recursive operations:
I think it's a great use of the rest syntax.
Anything is better than using
arguments
to get the arguments.Not necessary in JS, but this is very common in functional programming languages where loops constructs don't exist but all recursive calls are TCO (tail-call optimized)