3 ms·
Reminds me of VBA, where the way to “return” a value in a function is to assign it to the function’s name Sub f() 'returns 1 f = 1 End I always thought this
by bobbylarrybobby 5y ago
Reminds me of VBA, where the way to “return” a value in a function is to assign it to the function’s name
Sub f() 'returns 1
f = 1
End
I always thought this was insane, but it does make the semantics clear. Maybe not so insane after all
- TheSoftwareGuy 5y agoFORTRAN does the same actually
- masswerk 5y agoThis makes a point for separating the semantics of (a) control flow (a premature exit, similar to break in a loop) and (b) assigning return values. However, JavaScript actually started with rather quirky semantics for return: if any exit returned a value, all exits had to return a value, otherwise an error was thrown. Yet another effect of the nexus of control flow and assignment of a return value. (This got fixed with the introduction of the return object as workaround, which was, I think, in ECMA-Script 3.)