Key Concepts

Review core concepts you need to learn to master this subject

ReferenceError

// Example of a ReferenceError in JavaScript let firstName = "John"; // Here, we get a ReferenceError because lastName has not been declared console.log(firstName + lastName);

A ReferenceError is a type of error thrown when a variable is used that does not exist.

To prevent this error, all variables should be properly declared beforehand.

Debugging JavaScript Code
Lesson 1 of 2
  1. 1
    Any programmer will tell you that it is incredibly common to be making great progress working through a coding problem when all of a sudden an error like this gets thrown at you: /home/ccuser/work…
  2. 2
    We’ll start this lesson by taking a closer look at the most straightforward way to know your code isn’t working as expected: errors! You might recognize errors as the scary red text that appears …
  3. 3
    Now that we know what information we can get from an error stack trace, let’s take a look at an example. /home/ccuser/workspace/learn-javascript-debugging-code/app.js:1 myVariable; ^ ReferenceErr…
  4. 4
    Now that you can identify the type of error from an error stack trace, you might be wondering what the different types of errors mean. Here are three common error types: * SyntaxError: This er…
  5. 5
    Here’s a process for efficiently working through your code’s errors one by one: 1. Run your code. Using the first error’s stack trace, identify the error’s type, description, and location. 2. Go t…
  6. 6
    Errors thrown by the computer are really useful because they identify the bug type and location for you right away. However, even if your code runs error-free, it is not necessarily bug-free. You …
  7. 7
    Let’s synthesize our workflow from the previous exercise into a reusable set of debugging steps. 1. Go to the beginning of the malfunctioning code. Print out all starting variables, existing value…
  8. 8
    Sometimes once you’ve tracked down a bug, you might still be confused on how to fix it! Whenever you want to know more about how JavaScript works and what it can do, the best place to go is **docum…
  9. 9
    At this point, you might be thinking to yourself, documentation is good and all, but there’s no way it will solve all of my issues! And we totally agree. All programming languages have difficult pr…
  10. 10
    You just learned a lot of techniques for helping you get unstuck in all debugging situations. Congratulations! Let’s synthesize everything you learned into one debugging process. 1. **Is your code…

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo