Master object manipulation using object.assign, object.freeze, and proxies: Advanced Javascript

Vamsi Krishna Kodimela
Angular Simplified
Published in
4 min readJan 11, 2024

--

Object manipulation is one of the key concepts used by almost every JavaScript developer. While basic techniques like property assignment and object creation are essential, JavaScript offers more advanced methods for working with objects, providing flexibility, control, and immutability.

In this story, we’ll explore three powerful tools: Object.assign, Object.freeze, and proxies.

Object.assign: The Master of Merging

Object.assign is a built-in method that allows you to merge properties from multiple objects into a target object. It’s highly versatile and serves various purposes:

  • Combining objects: Create new objects with properties from multiple sources.
  • Cloning objects: Create shallow copies of objects, retaining their structure and values.
  • Default values: Set default properties for objects, ensuring they always have certain values.

Syntax:

Object.assign(target, source1, source2, ...);

Key Points:

  • Overwrites existing properties in the target object with those from the source objects.

--

--