-1

How can 2 objects be added through a js function without using 'join' that the result output below is true? This is the code that I have now:

 var twoObjs = function(obj1, obj2) {
 return obj1 + obj2; // does not work
};

twoObjs("dog", "ball");

var output = mergeObjs({dog: "Max"}, {toy: "mouse"});

console.log(output.cat === "Max")
console.log(output.toy === "mouse")
Amma
  • 177
  • 16

1 Answers1

2

You could use Object.assign to create a new object

var mergeObjs = function(obj1, obj2) {
    return Object.assign({},obj1,obj2);
};

var output = mergeObjs({
    dog: "Max"
}, {
    toy: "mouse"
});

console.log(output.dog)
console.log(output.toy)
adeneo
  • 312,895
  • 29
  • 395
  • 388