Merges two objects, preferring values from the first object when both are defined. If a property is undefined in the first object, the value from the second object is used.
Type of the first object
Type of the second object
The first object to merge
The second object to merge
A new object containing all properties from both input objects
const obj1 = { a: 1, b: undefined };const obj2 = { b: 2, c: 3 };const result = mergeObjects(obj1, obj2);// result is { a: 1, b: 2, c: 3 } Copy
const obj1 = { a: 1, b: undefined };const obj2 = { b: 2, c: 3 };const result = mergeObjects(obj1, obj2);// result is { a: 1, b: 2, c: 3 }
Merges two objects, preferring values from the first object when both are defined. If a property is undefined in the first object, the value from the second object is used.