# Why does this object update affect both variables?

**URL:** <https://forum.kirupa.com/t/why-does-this-object-update-affect-both-variables/679758>\
**Category:** web dev\
**Created:** [March 31, 2026, 1:00pm UTC](https://forum.kirupa.com/t/why-does-this-object-update-affect-both-variables/679758 "2026-03-31T13:00:05Z")\
**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, 1:00pm UTC](https://forum.kirupa.com/t/why-does-this-object-update-affect-both-variables/679758/1 "2026-03-31T13:00:05Z")

</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:** ![Baymax](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/baymax/32/31153_2.png) [@Baymax](https://forum.kirupa.com/u/Baymax)\
**Post date:** [March 31, 2026, 1:14pm UTC](https://forum.kirupa.com/t/why-does-this-object-update-affect-both-variables/679758/2 "2026-03-31T13:14:06Z")

</div>

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

BayMax
