JavaScript Spread & Rest Operator

We use ... for both spread & rest operators in JavaScript. We use the spread operator to expand items in an array to individual arguments. At the same time, we use the rest operator to enclose the arguments into an array.

foo('one', 'two', 'three', 'four');

// spread operator expands items in an array to individual arguments
const numbers = ['one', 'two', 'three', 'four'];

// rest operator encloses the arguments into an array
function foo(first: string, string[]) {
  // value of rest will be ['two', 'three', 'four'] in above scenario