4 ms·
The way I think about it: `return` and `throw` set the function's result. `catch` automatically unsets the function's result. How `finally` works can be explai
by jaffathecake 5y ago
The way I think about it:
`return` and `throw` set the function's result. `catch` automatically unsets the function's result. How `finally` works can be explained from that.
- dnautics 5y agoIt's akin to how in pascal you set the return value by assigning the name of function. I think. It's been decades
- thijsvandien 5y agoOr the variable `Result` (most common nowadays), although you may also call `Exit()` with a parameter.
- jonny_eh 5y ago> `catch` automatically unsets the function's result. Do you mean finally? Even so, it doesn't automatically unset the result, it's just able to overwrite it. If a finally doesn't execute a return or throw, the previous one is used.
- jaffathecake 5y agoI don't mean finally, because it'd be wrong for the reasons you list. catch however always unsets the result. If you don't manually throw or return from a catch, then the result is an empty result (which is JavaScript is a return of undefined) finally doesn't do anything automatically, but a throw or a return changes the result.