In JavaScript, the interaction between return
, await
, and finally
can cause subtle issues that developers should be aware of. Here are some key gotchas:
- The
finally
block runs regardless of whether areturn
,throw
, or an exception occurs intry
orcatch
. - If
finally
has areturn
, it overrides any return value or thrown error fromtry
orcatch
.
function test() {
try {
return "from try";