In the next video, you'll learn how you can pass individual elements into a function and have them treated as an array or an object using rest parameters.
Well that was quite exciting, wasn’t it? Sending individual parameters as functions and receiving them as an array inside the function? This way you are not concerned about how many arguments the user passes inside a function.
Do you remember about arguments object from the module on Basic Javascript? Well, rest parameters can be an alternative to the arguments keyword. Let us see how they can do this.
Well that was interesting, wasn’t it? But do remember to use rest operators should be written at the end inside the function declaration and not in the middle of a set of arguments.
There’s yet another place where the rest parameters are useful. This is in the case of arrow functions. Let’s look at arrow functions with rest parameters in the next video.
To summarise, the spread operator and rest parameters are vice-versa of each other. The spread operator is used to transform an array into its individual elements whereas the rest parameters are used to transform individual elements into an array. Also, the spread operator is used when calling a function whereas the rest parameters are used in the function parameters.