Back to Home

JavaScript Errors

Complete guide to JavaScript runtime errors, exceptions, and how to fix them.

11 Error Types
ReferenceError
Variable is not defined

Occurs when trying to access a variable that has not been declared or is out of scope.

console.log(x); // ReferenceError: x is not defined
TypeError
Cannot read property of undefined

Occurs when trying to access a property or method on an undefined or null value.

let obj = null; console.log(obj.property); // TypeError: Cannot read property 'property' of null
SyntaxError
Unexpected token

Occurs when the JavaScript parser encounters invalid syntax in the code.

let x = { // SyntaxError: Unexpected token
RangeError
Maximum call stack size exceeded

Occurs when a function calls itself too many times, causing a stack overflow.

function recurse() { recurse(); } recurse(); // RangeError: Maximum call stack size exceeded
URIError
Malformed URI

Occurs when using URI-related functions with invalid URI sequences.

decodeURIComponent('%'); // URIError: Malformed URI sequence
EvalError
Eval execution error

Occurs when there's an error in the eval() function. Rarely used in modern JavaScript.

eval('invalid code'); // EvalError
Promise Rejection
Unhandled promise rejection

Occurs when a Promise is rejected but no catch handler is provided.

Promise.reject('error'); // Unhandled promise rejection
Module Not Found
Cannot find module

Occurs when trying to import a module that doesn't exist or the path is incorrect.

import something from './non-existent'; // Error: Cannot find module
InternalError
Internal JavaScript engine error

An internal error in the JavaScript engine occurred, often due to too much recursion or other engine limitations.

function deep() { return deep(); } deep(); // InternalError: too much recursion
AggregateError
Multiple errors occurred

Multiple errors were wrapped together, commonly used with Promise.allSettled() or Promise.any().

Promise.allSettled([Promise.reject('error1'), Promise.reject('error2')]); // AggregateError
DOMException
DOM operation failed

A DOM operation failed, such as invalid node operations or security violations.

document.querySelector('#nonexistent').remove(); // DOMException: Cannot read property 'remove' of null