The rest parameter

In JavaScript, the rest parameter is a feature that allows a function to accept an indefinite number of arguments as an array.

Here are some examples:

const myFuncA = (a, b, ...manyMoreArgs) => {
  console.log("a", a);
  console.log("b", b);
  console.log("manyMoreArgs", manyMoreArgs);

myFuncA("one", "two", "three", "four", "five", "six");

const myFuncB = (...args) => {
  console.log("args:", args);
  console.log("...args", ...args);

myFuncB("hello", "world");

Did you find it interesting? Follow me on Twitter.

Leave a Reply

Your email address will not be published. Required fields are marked *