Plenty of π
Module 6: Errors, Debugging, and Troubleshooting
Common JS Exception Types

JavaScript has several built-in error object types that are thrown when runtime errors occur.

  • SyntaxError: An error in the code's syntax. Usually caught during parsing. Example: let x = 5y;

  • ReferenceError: Thrown when trying to access a variable that has not been declared or is not in scope. Example: console.log(undeclaredVariable);

  • TypeError: Thrown when an operation cannot be performed, typically when a value is not of the expected type. Examples:

    • Calling something that is not a function: let x = 10; x();
    • Accessing properties of null or undefined: let obj = null; obj.property;
    • Using an operator on an incompatible type: (10).split('');
  • RangeError: Thrown when a numeric variable or parameter is outside of its valid range. Examples:

    • new Array(-1) (Array length cannot be negative)
    • (10).toFixed(101) (Number of digits for toFixed is out of range 0-100)
  • URIError: Thrown when a global URI handling function (like encodeURIComponent(), decodeURI()) was used in a way that is incompatible with its definition.

  • Error (Generic): A base type for all errors. Sometimes generic errors are thrown, or custom errors inherit from this.

Understanding these common error types helps you quickly identify the nature of a problem when it appears in the console.