In relation to: Java try-finally return design question
This doesn't quite answer my question also may not be relevant since it's java and not javascript: What is the order of execution in try,catch and finally
I understand that putting a return in a finally
block will take precedence over a return in a catch
block, however how does the sequence events work with the following code?
function confusion(){
var test = "a";
try{
return test;
}
finally{
test = "b";
}
}
console.log("Result", confusion()); //"a"
My general understanding of returning of anything is that control usually returns to the context of where the method is being called, so the fact that execution continues is kind've confusing to me.
In this scenario I thought it might play out something like:
-Function set to return test
-> finally
changes value of test
-> test
is returned with updated value.
But instead it seems like some sort've state is held for the try
block and finally
misses the timing?