In most cases (including this one), return
will exit immediately. However, if the return is in a try
block with an accompanying finally
block, the finally
always executes and can "override" the return
in the try
.
function foo() {
try {
for (var i = 0; i < 10; i++) {
if (i % 3 == 0) {
return i; // This executes once
}
}
} finally {
return 42; // But this still executes
}
}
console.log(foo()); // Prints 42