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.
A SyntaxError is a type of error that is thrown when there is a typo in the code, creating invalid code - code which cannot be interpreted by the compiler.
Some common causes of a SyntaxError are:
- Missing opening or closing brackets, braces, or parentheses
- Missing or invalid semicolons
- Misspelling of variable names or functions
A TypeError is a type of error thrown when an attempt is made to perform an operation on a value of the incorrect type.
One example of a TypeError is using a string method on a numerical value.
An error stack trace tells a developer that it has detected an error within the code. Along with, which line to find the error, what type of error has occurred and a description of the error.
throw keyword is placed before an
Error() function call or object in order to construct and raise an error. Once an error has been thrown, the program will stop running and any following code will not be executed.
message property. An error created with this function will not stop a program from running unless the
throw keyword is used to raise the error.
catch statement can anticipate and handle thrown errors (both built-in errors as well as those constructed with
Error()) while allowing a program to continue running. Code that may throw an error(s) when executed is written within the
try block, and actions for handling these errors are written within the
- 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 …
- 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…
- 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…
- 1There are two categories of programming mistakes: those that don’t prevent our code from running and those that do. Sometimes, we’ve written code that successfully returns a value but a different…
- 2Errors contain useful messages that tell us why our program isn’t working or why the error was thrown. When an error is thrown, our program stops running and the console displays the error messag…
- 5Up to this point, thrown errors have caused our program to stop running. But, we have the ability anticipate and handle these errors by writing code to address the error and allow our program to…
- 7Great job with handling errors! In this lesson we went over: How mistakes in programming leads to errors. Why errors are useful for developers. * Errors will prevent a program from executing u…