Programming foundations

Stage 1 · Lesson 8 of 10

Errors, try/catch and debugging

Your first language

When something goes wrong, JavaScript an error object. It has a name, a message and a , the list of calls that led there. Read the first line in the terminal or the browser console.

TypeError: Cannot read properties of undefined usually means a value you expected was missing one step earlier. Error handling for expected failures uses try, catch and finally. A good example is with JSON.parse when the text may not be valid.

Throw your own errors with throw new Error("amount must be positive"). Do not wrap everything in try and silently ignore the error, because that hides bugs. When the output is wrong but there is no error, use a debugger.

Set a breakpoint in VS Code or the browser , then step through line by line, watching the variables.

A question to check yourself, an AI practice session and 2 cheat sheet entries come when you add the roadmap to your account. Add it

Resources for this stage

Start with· follow one of these

  • CoursePaid
    Grokking JavaScript Fundamentals

    Design Gurus · Beginner · $50

    The language itself, closures and async included, with runnable exercises per lesson

  • GuideFree
    JavaScript.info

    Ilya Kantor

    Free: Part 1 is the most complete modern JavaScript tutorial, with tasks per chapter

Practise

  • Small exercises in your language track, with free feedback from a human mentor

  • Foundations path: the JavaScript basics lessons and the exercises repo with tests

Keep handy

  • The JavaScript reference: look up every array and string method here

Mark this stage as not done?