Explorer
Node.js

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 }; } ```

Spread Operator - Merge Objects

Easy
Write a function `mergeObjects(obj1, obj2)` that merges two objects using the spread operator. Properties in `obj2` should override those in `obj1`.
Editor
Loading Editor...
Evaluate code
Output:Click "Run" above to execute and verify your code here.
{"a":1,"b":3,"c":4}