Write a function `mergeObjects(obj1, obj2)` that merges two objects using the spread operator. Properties in `obj2` should override those in `obj1`.
Problem Statement
Write a function `mergeObjects(obj1, obj2)` that merges two objects using the spread operator. Properties in `obj2` should override those in `obj1`.
Complexity
Time Complexity: -
Space Complexity: -
Hints
š” Hint 1:
The spread operator (...) can be used to copy properties from one object to another.
š” Hint 2:
When spreading multiple objects, later properties override earlier ones.
š” Hint 3:
return { ...obj1, ...obj2 };
ā
Solution:
```javascript
function mergeObjects(obj1, obj2) {
return { ...obj1, ...obj2 };
}
```