Caffeinated Coder
Book an appointment
Lesson 16 · How JavaScript really works

Errors and exceptions

When something goes wrong, JavaScript code can throw: the running function stops at once and an Error object travels down the call stack until a try block catches it, or the script stops. Follow thirteen real lines, root.js, as root(9) returns normally, root(-4) throws a RangeError, catch prints it, and finally runs last.

12 min11 steps5 questionsIntermediate
Fig 16 · Interactive
Loading figure…
or ← →

Quiz Unlocks after the last step.