# Avoid "node" as a variable name in functions

**URL:** https://discourse.nodered.org/t/avoid-node-as-a-variable-name-in-functions/18924
**Category:** General
**Created:** [8 December 2019 19:24 UTC](https://discourse.nodered.org/t/avoid-node-as-a-variable-name-in-functions/18924 "2019-12-08T19:24:47Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)
#### Post date: [8 December 2019 19:24 UTC](https://discourse.nodered.org/t/avoid-node-as-a-variable-name-in-functions/18924/1 "2019-12-08T19:24:47Z")

</div>

It took me a few minutes to sort this one out. The code in my (demo) `function` node is:

```auto
node.warn('hello world');
var node = 'hello world';
node.warn('hello world');
return msg;

```

The third line throws an error, "TypeError: node.warn is not a function"

I guess it's clear what is happening. There probably is no need for a warning in the documentation, unless there are other keywords that should be avoided. (I haven't had time to think about it.)

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [8 December 2019 19:26 UTC](https://discourse.nodered.org/t/avoid-node-as-a-variable-name-in-functions/18924/2 "2019-12-08T19:26:42Z")

</div>

I beleive I bumped into this at one point and spent some time pulling my hair out 😁

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [8 December 2019 19:56 UTC](https://discourse.nodered.org/t/avoid-node-as-a-variable-name-in-functions/18924/3 "2019-12-08T19:56:14Z")

</div>

🤣

You might want to avoid `RED` as well 😀

---

<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 December 2019 20:33 UTC](https://discourse.nodered.org/t/avoid-node-as-a-variable-name-in-functions/18924/4 "2019-12-08T20:33:35Z")

</div>

I'd suggest avoiding everything we document as being already-defined in the Function node - [https://nodered.org/docs/user-guide/writing-functions#api-reference](https://nodered.org/docs/user-guide/writing-functions#api-reference)

---

<div class="post-metadata">

### Author: ![tilleul](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tilleul/32/78_2.png) [@tilleul](https://discourse.nodered.org/u/tilleul)
#### Post date: [8 December 2019 21:40 UTC](https://discourse.nodered.org/t/avoid-node-as-a-variable-name-in-functions/18924/5 "2019-12-08T21:40:26Z")

</div>

Sorry but this is pure JS .... Node-RED exposes a variable/object named "node"... if you redefine it as a string, of course the original functions/methods/properties will be deleted and it won't work ...  
Also do not redefine `RED` or `undefined` and many others...

---

<div class="post-metadata">

### Author: ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)
#### Post date: [9 December 2019 17:07 UTC](https://discourse.nodered.org/t/avoid-node-as-a-variable-name-in-functions/18924/6 "2019-12-09T17:07:15Z")

</div>

> [@tilleul](#):
>
> Sorry but this is pure JS

Well yes, that's why I said it's clear what's happening, but no it's also a Node-RED issue since it was not obvious to me exactly what objects are exposed in the `function` node sandbox. The page @knolleary linked is helpful, assuming it is complete and stable.

> [@tilleul](#):
>
> do not redefine `RED` or `undefined` and many others...

This may confuse some folks. "`undefined` and many others" presumably refers to JS reserved names. On the other hand, `RED` is a NR-defined object, and as far as I can see from the documentation, the only others like it are `node`, `context`, `flow`, and `global`. Please let me know if I have missed something.

---

<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: [9 December 2019 17:18 UTC](https://discourse.nodered.org/t/avoid-node-as-a-variable-name-in-functions/18924/7 "2019-12-09T17:18:44Z")

</div>

> [@drmibell](#):
>
> Please let me know if I have missed something.

The link I gave you lists all of the pre-defined variables within the Function node.

I think it is reasonable for you to assume it is complete and stable.

---

<div class="post-metadata">

### Author: ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)
#### Post date: [9 December 2019 17:20 UTC](https://discourse.nodered.org/t/avoid-node-as-a-variable-name-in-functions/18924/8 "2019-12-09T17:20:40Z")

</div>

> [@knolleary](#):
>
> I think it is reasonable for you to assume it is complete and stable.

Thanks! I didn't mean to imply otherwise. 🙂
