JavaScript Errors and Debugging for Pythonistas (Summary)

Congratulations, you made it to the end of the course! Joan’s donation import now runs in JavaScript as node donations.js october.csv. It prints the same summary line as donations.py, 6 rows, 4 rejected, total £125.00, and rejects the same four rows by line number. The reasons use parseAmount()’s own messages, and the refund reads -40 where Python says -40.0.

A missing export gets No such file: missing.csv and exit code 1, and an unexpected row, such as a short one, still crashes the program so Joan notices.

In this course, you learned how to:

  • Catch the errors you expect with try, catch (err) and finally, limiting the try block to the call that can fail
  • Check for a key with Object.hasOwn(), or provide a default value for a missing key with ?? 0, instead of catching a miss that never throws
  • Throw an Error, a RangeError or a TypeError whose message says what arrived
  • Filter inside the catch with instanceof and err.code, and rethrow the rest
  • Read the trace of your own error from the top, where the second frame usually names the caller that passed the bad value
  • Log values with labels, in full and at every level with console.error() and console.dir(), list records with console.table(), and ask console.trace() who called a function

Keep the Habits That Carry Over

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.