# Function node & var definition

**URL:** <https://discourse.nodered.org/t/function-node-var-definition/71492>\
**Category:** General\
**Tags:** function-node\
**Created:** [30 November 2022 08:17 UTC](https://discourse.nodered.org/t/function-node-var-definition/71492 "2022-11-30T08:17:27Z")\
**Posts on this page:** 1\
**Showing post:** 32

<div class="post-metadata">

**Author:** ![ralphwetzel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ralphwetzel/32/53713_2.png) [@ralphwetzel](https://discourse.nodered.org/u/ralphwetzel)\
**Post date:** [1 December 2022 08:57 UTC](https://discourse.nodered.org/t/function-node-var-definition/71492/32 "2022-12-01T08:57:55Z")

</div>

> [@Colin](#):
>
> What I don't understand is how the old function apparently populated all of them.

This looks like a [design glitch in Node-RED](https://github.com/node-red/node-red/blob/14e74afb070081b10cbf4bb3f169692993c06155/packages/node_modules/%40node-red/nodes/core/function/10-function.js#L339) ... or perhaps a feature:  
The function node uses a `sandbox` (`node.js` terminology: _context_) that is initialized once and used throughout the life of the node. This sandbox acts like `globalThis`, explicitly [proposed to run several scripts](https://nodejs.org/api/vm.html#vmcreatecontextcontextobject-options) within that (preserving) context. Changes to the global scope (like variables defined accidentally globally by omitting `let` & friends) thus are reflected in `sandbox` and available for the next run of the function node.

I would like to propose @knolleary to verify if this is the intended functionality...

---

_[View the full topic](https://discourse.nodered.org/t/function-node-var-definition/71492)._
