DEV Community

Discussion on: Rest vs Spread Operator

Collapse
 
bryce profile image
Bryce Dorn

Hi, your rest example is actually still just spread syntax! The definition you included is correct:

Rest: allows a function to accept an indefinite number of arguments as an array

But your example isn't a function. Here's what it would look like using rest:

function logFullName(firstName, ...familyName) {
  console.log(firstName);
  console.log(familyName);
}

logFullName("Robert", "Alfred", "Cole");
Enter fullscreen mode Exit fullscreen mode
Collapse
 
melguachun profile image
Melissa Guachun

Ah! Thank you for pointing that out! I'll make that change, thanks Bryce!