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
Clean up after a failure
easy10 minRecord the three steps in order.
- 2
Clean up after success
easy10 minShow that finally runs when nothing failed.
- 3
Clear a loading flag
easy10 minTurn the flag off whatever happens.
- 4
Run before a return
easy10 minShow that finally runs even when the try block returns.
- 5
Use finally without catch
medium10 minClean up but let the error keep travelling.
Find the bug(5)
- 1
Fix the cleanup repeated in both branches
easy8 minfinally does the job once instead of twice.
- 2
Fix the cleanup skipped on failure
easy8 minCleanup placed in the try block is skipped when it throws.
- 3
Fix the return from finally
easy8 minA return in finally overrides the one in try.
- 4
Fix the order recorded wrongly
easy8 minfinally runs last, after the catch.
- 5
Fix the error swallowed by finally
easy8 minThe 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