Functions in JavaScript provide a lot of power and versatility of use to power our applications. A big part of that logic is the dynamic nature of being able to manipulate logic and/or values by passing in identified parameters. Typically functions take in a set set of parameters, however, there is a way to build a function that can take in an unlimited number of parameters. That’s by using the rest parameter concept.

Enough talk though, let’s look at some code!

const combineString(...rest) {
  let finalString = '';
  for (const arg of theArgs) {
    finalString += `${arg} `;
  }
  return finalString;
}

combineString(1,2,'hi',3)
// '1 2 hi 3 '