DEV Community

Cover image for FrontEnd Interview Series
TheDev
TheDev

Posted on

2

FrontEnd Interview Series

Why Changing a Copy Affects the Original Objects in JavaScript ? 🤔

Ever faced a situation in your JavaScript code where assigning an object or array to another variable and then modifying it unexpectedly changes the original? It’s not a mystery—this is how JavaScript handles object references.

To understand this behaviour you need to understand few things in details

  1. Reference Types: Why changes to one object affect the other.
  2. Shallow Copies: Techniques using the spread operator and Object.assign().
  3. Deep Copies: Leveraging structuredClone() and crafting a Custom Deep clone function.

I have explained and coded all these concept in my latest video
Watch the full video here:

💬 Have questions or insights? Share them in the comments below, and let's dive into the discussion!

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more