It is supported but strongly discouraged. If you really want to write bad code (my opinion), let me know and I'll point you to the settings that will permit that.
why would you want to do this? If you want to retain a variable outside of the function node scope, you can use context variables.
In any case, relying on external variables (as opposed to message properties) can introduce race conditions between multiple concurrent flows (or runs of the same flow).
Hi, actually I don't, just wanted to understand the behavior, why it works in some Js examples but not in NR.
Bus as I said I'll tweak the code to use it the proper way.
As others have said, it is best to use best practices from the outset. Use of const where you don't need to later replace the variable's value, otherwise use of let. Both of these constrain the context of the resulting variable to help avoid hard to track down bugs in your code.
In extreme situations, you might still choose to use var - I sometimes get lazy in a function node and if I want to specify a variable but wrap it in a try/catch, and I might use a var there simply for speed. But it is still bad practice.
I always thought that, if not specified, then js defaulted to var rather than something different. Is an unspecified type actually functionally different to var other than that it produces warnings in the syntax checker?
If you don't declare a variable at all, this is what happens:
The variable automatically becomes global (even if inside a function).
It is not hoisted, so it only exists after assignment.
It implicitly becomes a property of the global object.
Whereas declaring with var:
The variable is scoped to the function if defined in one. It becomes a property of the global object (in browsers, window) if defined outside a function.
It is automatically hoisted to the top of its scope but initialized as undefined. So you can use it BEFORE you've defined it.