Finally always wins, unless you crash your computer meanwhile

11th February 2014 | by Adam Beres-Deak | javascript, fun

In JavaScript it is perfectly valid to have a return statement in a finally block. But this doesn't mean, you should really put it in there. Consider the following code:

function whatDoesThisReturn() {
    try {
        return false;
    } finally {
        return true;


Basically the finally block is called after the try block, therefore it overrides the return value.

So this function returns true.

by Adam Beres-Deak

| Share | Tweet | Share | Share

Latest blog posts

Displaying icons with custom elements 14th October 2015

Plain JavaScript event delegation 26th January 2015

After the first year of blogging - what happened on my blog in 2014? 1st January 2015

Better webfont loading with using localStorage and providing WOFF2 support 18th December 2014

Worth watching: Douglas Crockford speaking about the new good parts of JavaScript in 2014 20th October 2014