Errors and Error Handling
Learn how to address errors in this course all about JavaScript errors!
StartKey Concepts
Review core concepts you need to learn to master this subject
ReferenceError
MDN JavaScript error documentation
SyntaxError
TypeError
Javascript error stack trace
Javascript documentation
Runtime Error in JavaScript
The throw
Keyword in JavaScript
ReferenceError
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
- 1Any 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…
- 2We’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 …
- 3Now 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…
- 4Now 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…
- 5Here’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…
- 6Errors 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 …
- 7Let’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…
- 8Sometimes 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…
- 9At 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…
- 10You 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