The Rest Parameter allows you to do two things: (1) break out the first X arguments passed-into the function, and (2) put “the rest” of the arguments into an array.
Using the Rest Parameter – Example # 1 A
inspectArgs Output – Example # 1 B
So, the key point here is that by placing “…theArgs” where the incoming arguments would normally go, we are saying: “take all of the arguments that are passed-into this function, put them into an array, and create a local variable for this function named theArgs”. And in Example # 1 B, you can see the output of Example # 1 A, which is exactly what we expect: the value of each argument that was passed to the inspectArgs function.
When you actually want “the rest” of the arguments – Example # 2 A
We See the First Argument, and “the rest” of them- Example # 2 B
Now if we take a look at Example # 2 B, we see the output of Example # 2 A. As expected, we see “x -> a” first, because we examined the first argument. Then we see the “rest” of the arguments, because we used the rest parameter to iterate the “rest of” the arguments that were passed into the function.
Skipping Arguments – Example # 3 A
The Second Argument Has Been Skipped – Example # 3 B