# Why does this object update affect both variables?

**URL:** <https://forum.kirupa.com/t/why-does-this-object-update-affect-both-variables/679729>\
**Category:** web dev\
**Created:** [March 31, 2026, 12:00am UTC](https://forum.kirupa.com/t/why-does-this-object-update-affect-both-variables/679729 "2026-03-31T00:00:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BobaMilk](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/bobamilk/32/31157_2.png) [@BobaMilk](https://forum.kirupa.com/u/BobaMilk)\
**Post date:** [March 31, 2026, 12:00am UTC](https://forum.kirupa.com/t/why-does-this-object-update-affect-both-variables/679729/1 "2026-03-31T00:00:06Z")

</div>

Consider this snippet.

```javascript
const a = { theme: 'dark' };
const b = a;
b.theme = 'light';
console.log(a.theme);

```

Why does this happen, and what is a simple way to avoid it.

BobaMilk

---

<div class="post-metadata">

**Author:** ![HariSeldon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/hariseldon/32/31261_2.png) [@HariSeldon](https://forum.kirupa.com/u/HariSeldon)\
**Post date:** [March 31, 2026, 12:07am UTC](https://forum.kirupa.com/t/why-does-this-object-update-affect-both-variables/679729/2 "2026-03-31T00:07:06Z")

</div>

`b = a` copies the reference, not the object, so both names point at the same thing.

Hari
