# Global context mutability

**URL:** <https://discourse.nodered.org/t/global-context-mutability/22407>\
**Category:** General\
**Created:** [29 February 2020 12:54 UTC](https://discourse.nodered.org/t/global-context-mutability/22407 "2020-02-29T12:54:18Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [29 February 2020 13:13 UTC](https://discourse.nodered.org/t/global-context-mutability/22407/2 "2020-02-29T13:13:16Z")

</div>

JavaScript passes objects by reference and we don't automatically clone them for you for performance reasons. If you want to modify the object without affecting context, you have to clone it or rebuild it.

> [@Global.put not needed as variable altered by reference?](https://discourse.nodered.org/t/global-put-not-needed-as-variable-altered-by-reference/20511/5):
>
> JavaScript passes objects around by reference rather than by value. So the call to global.get() returns a reference to the object in context. Any modification of the object will modify the object in context. If you want to modify the object without modifying what is in context, you have to clone it first. We provide the RED.util.cloneMessage function that can be used for this: var value = RED.util.cloneMessage( global.get("myValue") );

---

_[View the full topic](https://discourse.nodered.org/t/global-context-mutability/22407)._
