# Another weird happening with \`msg\` and \`null\`

**URL:** <https://discourse.nodered.org/t/another-weird-happening-with-msg-and-null/101172>\
**Category:** General\
**Created:** [1 June 2026 23:39 UTC](https://discourse.nodered.org/t/another-weird-happening-with-msg-and-null/101172 "2026-06-01T23:39:43Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [1 June 2026 23:39 UTC](https://discourse.nodered.org/t/another-weird-happening-with-msg-and-null/101172/1 "2026-06-01T23:39:43Z")

</div>

I am really having fun with _rogue_ messages and strange things happening in my flows.

(my thread on subflows for buttons for instance)

So I'm confused with what I am seeing and to maybe save me a lot of typing here is a picture which I think clearly shows what I see as the problem.

 ![Screenshot from 2026-06-02 09-35-44](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/e/7e0112f6854a26e1acdf485fbe13a1bcb0d72c87.png)

And before anyone mentions it:  
I have tried with no `topic`. SAME.

Why?

If a message isn't sent: how can OUT be created?

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [1 June 2026 23:59 UTC](https://discourse.nodered.org/t/another-weird-happening-with-msg-and-null/101172/2 "2026-06-01T23:59:58Z")

</div>

Just because the payload is null does not mean there is no message.

Obviously as can be seen by your debug there is indeed a message sent and the payload has been sent to Null - remember a message is a javascript object so it still has other properties such as topic etc

Craig

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [2 June 2026 00:19 UTC](https://discourse.nodered.org/t/another-weird-happening-with-msg-and-null/101172/3 "2026-06-02T00:19:00Z")

</div>

A bit of background on how all this happened:

A `function` node code - example:

```auto
if (x = 3)
{
    payload = "a"
}
else
{
    payload = "b"
}
msg.payload = payload
return msg

```

That is fine.

But if you make it:

```auto
if (x = 3)
{
    payload = "a"
}
else
{
    payload = null
}
msg.payload = payload
return msg

```

That's a whole other story.

And it is different to:  
`return null`

Here is an example flow that shows this problem with what happens in the `function` node and the `return` stuff.

```auto
[{"id":"a8d589a97ea51bd6","type":"inject","z":"6cf51e98651df17b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":2150,"y":3960,"wires":[["4934260b228560e0"]]},{"id":"4934260b228560e0","type":"function","z":"6cf51e98651df17b","name":"function 4","func":"if (msg.payload == \"A\")\n{\n msg.payload = \"ONE\"\n}\nelse\n{\n msg.payload = null\n}\nlet msg1 = {}\nmsg1.payload = null\nreturn [msg,msg1]","outputs":2,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2320,"y":3960,"wires":[["2a2a5d4f64c61a24"],["397d9434427bd94e"]]},{"id":"2a2a5d4f64c61a24","type":"change","z":"6cf51e98651df17b","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"Hello","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":2520,"y":3940,"wires":[["b3584d6abc3f725b"]]},{"id":"b3584d6abc3f725b","type":"debug","z":"6cf51e98651df17b","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2670,"y":3940,"wires":[]},{"id":"ddc48bb67e382bd8","type":"debug","z":"6cf51e98651df17b","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2670,"y":3980,"wires":[]},{"id":"397d9434427bd94e","type":"change","z":"6cf51e98651df17b","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"Hello","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":2520,"y":3980,"wires":[["ddc48bb67e382bd8"]]},{"id":"3008b7d591a739e7","type":"function","z":"6cf51e98651df17b","name":"function 5","func":"if (msg.payload == \"A\")\n{\n msg.payload = \"ONE\"\n}\nelse\n{\n msg.payload = null\n}\nreturn [msg,null]","outputs":2,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2320,"y":4040,"wires":[["d3acbad355dbc6d2"],["c3321f12e6d7e7d0"]]},{"id":"1c03674fbcc6a8a0","type":"inject","z":"6cf51e98651df17b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":2150,"y":4040,"wires":[["3008b7d591a739e7"]]},{"id":"d3acbad355dbc6d2","type":"change","z":"6cf51e98651df17b","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"Hello","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":2520,"y":4020,"wires":[["2f2da2919cf7c2b5"]]},{"id":"c3321f12e6d7e7d0","type":"change","z":"6cf51e98651df17b","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"Hello","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":2520,"y":4060,"wires":[["d10e0fb321c17e60"]]},{"id":"2f2da2919cf7c2b5","type":"debug","z":"6cf51e98651df17b","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2670,"y":4020,"wires":[]},{"id":"d10e0fb321c17e60","type":"debug","z":"6cf51e98651df17b","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2670,"y":4060,"wires":[]}]

```

That also shows this _problem_ happening.

(Screen shot for the sake of it.)

 ![Screenshot from 2026-06-02 10-16-54](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/e/4e1dd4032172ff2f66367f42cf0793915ea3037e.png)

Compare the code in `function 4` and `function 5`.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [2 June 2026 00:19 UTC](https://discourse.nodered.org/t/another-weird-happening-with-msg-and-null/101172/4 "2026-06-02T00:19:58Z")

</div>

Yes, and I did say that even if I deleted the `topic` it still happened.

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [2 June 2026 01:16 UTC](https://discourse.nodered.org/t/another-weird-happening-with-msg-and-null/101172/5 "2026-06-02T01:16:12Z")

</div>

yeah its not the fact that you delete the topic its the fact the the msg is an object with a number of standard inclusions (like msg.id for example)

### Key Considerations

- **Type Behavior** : Although `null` is a primitive value, `typeof null` returns `"object"` due to a historical bug in JavaScript.
- **Equality** : `null` is loosely equal (`==` ) to `undefined` but strictly not equal (`===` ).
- **Arithmetic** : In numerical operations, `null` converts to `0` (e.g., `2 + null` results in `2` ), whereas `undefined` results in `NaN` .
- **Object.assign** : You cannot use `null` as the target object for `Object.assign()` because it is not an object; attempting to do so will throw an error.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [2 June 2026 01:18 UTC](https://discourse.nodered.org/t/another-weird-happening-with-msg-and-null/101172/6 "2026-06-02T01:18:54Z")

</div>

Yeah, thanks.

I have kinda worked that out myself ITMT.

But thanks for confirming it.

Now I am have the fun job of replacing all the places I set `msg = {}` and so I can leave the `return [msg,msg1]` and put a `return [null,.msg1]` in place of the `msg = {}`

Which is kinda messy. But if that is the only way to do it, I guess it has to be done.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [2 June 2026 03:40 UTC](https://discourse.nodered.org/t/another-weird-happening-with-msg-and-null/101172/7 "2026-06-02T03:40:36Z")

</div>

> [@Trying\_to\_learn](#):
>
> `if (x = 3)`

If you want to test against a value you need to use `==`.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [2 June 2026 04:24 UTC](https://discourse.nodered.org/t/another-weird-happening-with-msg-and-null/101172/8 "2026-06-02T04:24:17Z")

</div>

Yes, but I just knocked up that code to explain the situation.

However, in light of all this new information I am slightly more intelligent hat I was before.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [2 June 2026 07:15 UTC](https://discourse.nodered.org/t/another-weird-happening-with-msg-and-null/101172/9 "2026-06-02T07:15:31Z")

</div>

> [@Trying\_to\_learn](#):
>
> Now I am have the fun job of replacing all the places I set `msg = {}` and so I can leave the `return [msg,msg1]` and put a `return [null,.msg1]` in place of the `msg = {}`

Just change `msg = {}` to `msg = null`

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [2 June 2026 08:22 UTC](https://discourse.nodered.org/t/another-weird-happening-with-msg-and-null/101172/10 "2026-06-02T08:22:35Z")

</div>

I'll try to remember this for next time.

I have lost track of what has happened.

I think I put a test in and if a condition is met, I replace the `return` line that returns the message with `null,msg1`

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [16 June 2026 08:22 UTC](https://discourse.nodered.org/t/another-weird-happening-with-msg-and-null/101172/11 "2026-06-16T08:22:52Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
