Skip to main content

JavaScript finally — exercises and bug fixes

5 hands-on exercises and 5 find-the-bug challenges for the JavaScript finally lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.

Exercises(5)

  1. 1

    Clean up after a failure

    easy10 min

    Record the three steps in order.

  2. 2

    Clean up after success

    easy10 min

    Show that finally runs when nothing failed.

  3. 3

    Clear a loading flag

    easy10 min

    Turn the flag off whatever happens.

  4. 4

    Run before a return

    easy10 min

    Show that finally runs even when the try block returns.

  5. 5

    Use finally without catch

    medium10 min

    Clean up but let the error keep travelling.

Find the bug(5)

  1. 1

    Fix the cleanup repeated in both branches

    easy8 min

    finally does the job once instead of twice.

  2. 2

    Fix the cleanup skipped on failure

    easy8 min

    Cleanup placed in the try block is skipped when it throws.

  3. 3

    Fix the return from finally

    easy8 min

    A return in finally overrides the one in try.

  4. 4

    Fix the order recorded wrongly

    easy8 min

    finally runs last, after the catch.

  5. 5

    Fix the error swallowed by finally

    easy8 min

    The inner block should clean up but still let the error escape.

Ready to write the code?

The editor, the automatic checks and the worked solutions open up with an account.

Open the workspace