# Global.put not needed as variable altered by reference?

**URL:** <https://discourse.nodered.org/t/global-put-not-needed-as-variable-altered-by-reference/20511>\
**Category:** General\
**Created:** [17 January 2020 17:32 UTC](https://discourse.nodered.org/t/global-put-not-needed-as-variable-altered-by-reference/20511 "2020-01-17T17:32:24Z")\
**Posts on this page:** 1\
**Showing post:** 5

<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:** [17 January 2020 22:52 UTC](https://discourse.nodered.org/t/global-put-not-needed-as-variable-altered-by-reference/20511/5 "2020-01-17T22:52:17Z")

</div>

> [@coppo23](#):
>
> Do you know exactly what conditions cause the global variable to be updated when I edit the local 'copy'?

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:

```auto
var value = RED.util.cloneMessage( global.get("myValue") );

```

---

_[View the full topic](https://discourse.nodered.org/t/global-put-not-needed-as-variable-altered-by-reference/20511)._
