Source code for scripting blocks seems to be interpreted as function code. For example, the following input executes successfully (writing the string "first" to the output container):
output.text('first');
return;
output.text('second');
Using return at the apparent top-level of a script can be useful for control flow in shorter scripts since it allows developers to exit early without throwing an error or wrapping their code in an immediately-invoked function expression.
On the other hand, the behavior is undocumented, and the scripting block’s editor flags it as a syntax error (“A ‘return’ statement can only be used within a function body.”). That makes it unclear whether developers should rely on it. It would be great if the developer documentation for the Scripting Block said something about whether authors can rely on this (and if so, the editor updated accordingly).
