Skip to content
Advertisement

Why does a return in `finally` override `try`?

How does a return statement inside a try/catch block work?

JavaScript

I’m expecting the output of this function to be true, but instead it is false!

Advertisement

Answer

Finally always executes. That’s what it’s for, which means its return value gets used in your case.

You’ll want to change your code so it’s more like this:

JavaScript

Generally speaking you never want to have more than one return statement in a function, things like this are why.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement