assign method of an object allows us to merge two objects quickly.

const name = { name: "earth" };
const position = { position: 3 };

const planets = Object.assign(name, position);
console.log("planets: ", planets); // { name: 'earth', position: 3 }

You can also use Object.assign to quickly copy objects.

const third = { name: "earth", position: 3 };
const livePlanet = Object.assign({}, third);
console.log("livePlanet: ", livePlanet);

third.position = 3.14;
console.log("third: ", third); // { name: 'earth', position: 3.14 }
console.log("livePlanet: ", livePlanet); // { name: 'earth', position: 3 }

If you do not provide the empty object to assign, only a reference is copied and not the object itself.