Why do I get different Javascript errors in Chrome's interpreter vs. Losant Function node?

I had this code in a Function node:

var test;
test.start_time_ms = 100;

This node returns an error: “Cannot set property ‘start_time_ms’ of undefined.”

If I switch to this, then the error goes away:

var test = {};
test.start_time_ms = 100;

Strangely, I am able to use the original example in Chrome’s console without any errors. The field/property start_time_ms seems to be created-on-assignment using Chrome, but not using the Function node.

Is the Function-node’s JS interpreter acting differently from Chrome’s in this situation, or is there another explanation?

Hmm. That’s odd.

Here is what I get in Dev Tools:

But, overall, I’d recommend using:

That way, you clearly create the object.


const test = { start_time_ms: 100 };

1 Like

Ah, my mistake - just checked again, and I get the same results as you. Not sure what happened the first time I tested. Thanks!

1 Like