Destructuring & Spread Operator
How can you use the spread operator to merge two objects?
You can use the spread operator to merge two objects by writing `const merged = {...obj1, ...obj2};`. This syntax creates a new object and copies all enumerable properties from both source objects into it. If both objects have properties with the same key, the value from the second object (obj2) will overwrite the value from the first (obj1). This is because properties are applied in order from left to right. This object spread syntax was introduced in ES2018 (though it was available earlier in many environments via transpilers). It provides a concise alternative to `Object.assign({}, obj1, obj2)`. Both methods create a shallow copy—if properties contain nested objects, those will still be references to the original objects. This pattern is commonly used in state management (like Redux reducers), when updating configuration objects, or when creating new objects based on existing ones with some modifications.