April 2018
Intermediate to advanced
284 pages
5h 46m
English
| Tip 31 | Pass a Variable Number of Arguments with the Rest Operator |
In this tip, you’ll learn to collect an unknown number of parameters with the rest operator.
In the previous tips, you saw how object destructuring would let you combine several parameters into a single argument.
Using objects to hold parameters is a great technique, but it’s really only useful in situations where the parameters are different and you know them ahead of time. In other words, it only makes sense in situations with objects.
That may seem obvious, but it raises the question: How do you handle an unknown number of similar parameters?
Think back to the photo display application. What if you wanted to allow your users to tag photos but you only wanted the tags to be ...
Read now
Unlock full access