Errors, Debugging and Testing
Read any error and its stack trace, handle failures with try/catch, throw helpful errors, debug in DevTools, write defensive code and test it.
Every program fails sometimes: a user types letters into a number box, a server sends back broken JSON, a variable is undefined when you thought it held an object. This phase is about failing well. You'll learn the kinds of error JavaScript has, how to read the red message and its stack trace, and how try, catch and finally let you handle a failure instead of letting it stop your script.
Then you'll throw your own errors with messages that tell the next person exactly what went wrong, using Error subclasses and the ES2022 cause option to keep the original error. You'll pause running code in DevTools with breakpoints, step through it line by line and watch values change, and you'll write defensive code that checks its input at the door and never fails silently.
Last, you'll write tests: small pieces of code that check your code, so a bug is caught by a machine before a user finds it. You'll build a tiny test helper inside the live examples and see how real test runners such as Vitest and Jest do the same job. This phase builds on functions (Phase 3), classes (Phase 7), promises and async/await (Phase 10) and tooling (Phase 12).
Practise this phase
Hands-on exercises: write the code, see your page live, and press Check to have it tested automatically.