+ 2
Spread Operator (JS)
const object1 = {foo: "bar", x: 42}; const object2 = {foo: "baz", y: 5}; const merge = (...objects) => ({...objects}); let mergeObject = merge(object1, object2); console.log(mergeObject); let mergeObject1 = merge({}, object1, object2); console.log(mergeObject1); Can anyone kindly explain what is happening in the merge function or how is it working? This is the last example from spread operator section of JS course. Having a hard time over this example. Playground link: https://code.sololearn.com/WA2177a20A21 Thanks in advance.
1 Respuesta
+ 1
In the merge function whatever you pass, it will actually be passed as a single parameter and returning the all.
As you have used spread operator, you can pass as more as parameter you want. All parameters will be passed as a single one.