# Pushing a local var updates the global one

**URL:** <https://discourse.nodered.org/t/pushing-a-local-var-updates-the-global-one/21414>\
**Category:** General\
**Created:** [8 February 2020 05:50 UTC](https://discourse.nodered.org/t/pushing-a-local-var-updates-the-global-one/21414 "2020-02-08T05:50:58Z")\
**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:** [8 February 2020 08:17 UTC](https://discourse.nodered.org/t/pushing-a-local-var-updates-the-global-one/21414/2 "2020-02-08T08:17:10Z")

</div>

Please see this topic for the explanation of this behaviour:

> [@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/pushing-a-local-var-updates-the-global-one/21414)._
