This is pretty interesting, but at first it might be hard to see the use case. ES6 also supports Object destructuring, which might make uses more obvious:
Destructuring can also be used for passing objects into a function, allowing you to pull specific properties out of an object in a concise manner. It is also possible to assign default values to destructured arguments, which can be a useful pattern if passing in a configuration object.
let jane = { firstName:'Jane', lastName:'Doe'};let john = { firstName:'John', lastName:'Doe', middleName:'Smith' }functionsayName({firstName, lastName, middleName ='N/A'}) {console.log(`Hello ${firstName}${middleName}${lastName}`) }sayName(jane) // -> Hello Jane N/A DoesayName(john) // -> Helo John Smith Doe
The spread operator allows an expression to be expanded in places where multiple arguments (for function calls) or multiple elements (for array literals) or multiple variables (for destructuring assignment) are expected.