Function node - what happens if I don't "return" anything?

I know I am asking for it by asking, but in light of wanting to learn.....

It probably isn't the reason, but I want to be sure.

My poor RPI is (I am told) running way to hard (60-70% load peaking.)
Now and then it goes up to 100% but only for a while.

Anyway, here's my question:

(Example code only)
(Hand written not real code, but only for showing the problem as I see it)

var x = msg.payload;
if (x == "foo")
{
   msg.payload = "Option 1";
  return msg;
}
else
if (x == "boo")
{
  msg.payload = "Option 2";
  return msg;
}

Which has not worried me until now.

If the message is neither "foo" or "boo" then nothing is sent.
That is what is wanted/needed.

Until know I thought (stupidly) that you had to return msg;

But a simple return is also allowed.
Though I have to admit, I don't get what is returned.

If I have a few (dozen) nodes without the final return would that cause problems?

Gotta ask to be sure.

A return by itself, return null, and no return at the end at all, all do the same, no message is sent.

2 Likes

Ok, that resolves that suspicion.

Easily tested though - you need to have confidence in your ability to test :slight_smile:

2 Likes

Yeah, as someone once said:

(this applies to me....)

I am good at testing dumb things I do.

But, I try to see the bright side of it. I am learning.