JavaScript Errors
50 errors
Common JavaScript errors and how to fix them.
50 / 50
- 1
ReferenceError: x is not defined
You referenced a variable name that JavaScript doesn't know about — it was never declared with `let`, `const`, or `var` in any accessible scope.
- 2
TypeError: x is not a function
You used parentheses to call a value, but that value is not a function — it's a number, string, object, or `undefined`.
- 3
TypeError: Cannot read properties of undefined
You used dot notation on a value that is `undefined` — the property doesn't exist because the object itself is missing.
- 4
TypeError: Cannot read properties of null
You used dot notation on a value that is `null` — `null` has no properties, so the access fails.
- 5
SyntaxError: Unexpected token
JavaScript found a symbol where it shouldn't be — usually a missing bracket, comma, or quote earlier in the code.
- 6
ReferenceError: Cannot access 'x' before initialization
You used a `let` or `const` variable before it was declared — JavaScript knows it exists (hoisting) but won't let you access it yet.
- 7
NaN Result
Your calculation resulted in `NaN` — usually because you mixed numbers with `undefined`, non-numeric strings, or other invalid values.
- 8
Promise Not Awaited
You called an async function without `await`, so you got a Promise object instead of the actual result you expected.
- 9
RangeError: Maximum call stack size exceeded
Your code has infinite or excessive recursion — a function calls itself without a proper base case, filling up the call stack until it overflows.
- 10
SyntaxError: Missing parenthesis after argument list
You called a function but forgot to close the parentheses, so JavaScript cannot parse the call.
- 11
TypeError: Cannot read properties of undefined (reading 'length')
You accessed .length on something that is undefined — usually a variable that was never assigned or a lookup that returned undefined.
- 12
RangeError: Invalid array length
You tried to create or resize an array with an invalid length — negative, non-integer, or too large.
- 13
SyntaxError: Identifier 'x' has already been declared
You declared a variable with the same name twice in the same scope using let or const — JavaScript does not allow this.
- 14
TypeError: x is not iterable
You tried to iterate over something that is not iterable — for...of and spread only work on arrays, strings, Maps, Sets, and other iterables.
- 15
UnhandledPromiseRejection
A Promise was rejected (failed) but you did not provide an error handler — the rejection goes unhandled, which may crash the app.
- 16
SyntaxError: Unexpected end of input
Your code has an unclosed bracket, brace, parenthesis, or template literal — JavaScript ran out of input while still parsing.
- 17
TypeError: Cannot assign to read only property
You tried to assign a value to a property that is read-only — the object was frozen or the property was defined as non-writable.
- 18
RangeError: Invalid code point
You called String.fromCodePoint() with a value that is not a valid Unicode code point — it must be a non-negative integer up to 0x10FFFF.
- 19
SyntaxError: Unexpected token in JSON
You called JSON.parse() on a string that does not conform to JSON syntax — JSON requires double-quoted keys and string values, no trailing commas, no comments.
- 20
TypeError: Converting circular structure to JSON
Your object contains a circular reference (a property that points back to the object itself), which JSON.stringify cannot handle because it would loop forever.
- 21
URIError: URI malformed
You passed a malformed URI string to decodeURIComponent() — it contains invalid percent-encoded sequences.
- 22
SyntaxError: Duplicate parameter name not allowed in this context
You declared a function with duplicate parameter names while in strict mode — this is not allowed.
- 23
TypeError: Promise resolver is not a function
You called new Promise() with an argument that is not a function — the Promise constructor expects an executor function (resolve, reject) => {}.
- 24
TypeError: Assignment to constant variable
You declared a variable with const and then tried to assign a new value to it — const variables cannot be reassigned.
- 25
RangeError: Invalid Date
You passed an invalid value to the Date constructor, resulting in an Invalid Date object that returns NaN for all methods.
- 26
DOMException: Blocked a frame with origin from accessing a cross-origin frame
You tried to access an iframe, window, or document from a different origin — the Same-Origin Policy blocks this for security.
- 27
SyntaxError: Unexpected token < in JSON
You called JSON.parse() on a response that is HTML, not JSON — usually an API error page or a redirect to a login page.
- 28
TypeError: Reduce of empty array with no initial value
You called array.reduce() on an empty array without a second argument (initial value) — reduce has nothing to start with.
- 29
TypeError: Cannot read properties of null (reading 'addEventListener')
You tried to add an event listener to an element that does not exist in the DOM — the selector returned null.
- 30
SyntaxError: Illegal return statement
You used `return` outside of a function body — return is only valid inside functions.
- 31
TypeError: x.replace is not a function
You called .replace (or .trim, .split) on a number, array, or object — those methods only exist on strings.
- 32
RangeError: Invalid repeat count
You passed a negative number, Infinity, or a huge count to .repeat — the result cannot be a valid string.
- 33
TypeError: Cannot mix BigInt and other types
You added or compared a BigInt with a Number — JavaScript does not implicitly convert, so the operation fails.
- 34
TypeError: Invalid value used as weak map key
You called weakMap.set('key', value) with a string key — WeakMap only accepts objects as keys.
- 35
TypeError: object is not iterable
You spread {...obj} or ran for...of on a plain object — objects are not iterable by default.
- 36
RangeError: flat depth too large
You passed a huge depth (or Infinity) to .flat — the recursive flattening runs out of stack space.
- 37
RangeError: toFixed() digits argument must be between 0 and 100
You passed a negative or very large precision to .toFixed — only 0–100 is allowed.
- 38
SyntaxError: Unexpected newline after arrow
You wrote => on one line and the body on the next — the parser treats the arrow as having no body.
- 39
SyntaxError: Invalid shorthand property initializer
You wrote { 1+1 } or { foo() } in an object literal expecting shorthand, but shorthand only works with identifiers.
- 40
SyntaxError: Optional chaining cannot be used with new
You wrote new?.Foo() — the parser rejects it because new and ?. cannot combine.
- 41
SyntaxError: Undefined label
You wrote break outerLoop but no label named outerLoop encloses the loop — the target does not exist.
- 42
SyntaxError: Export before declaration
You referenced a name in an export statement before it was declared — the module cannot resolve the binding.
- 43
SyntaxError: Identifier already declared in class body
You defined two methods with the same name in a class — the parser rejects the duplicate.
- 44
Array.sort default lexicographic order
You called .sort() on a number array without a comparator — it sorted as strings, so [10, 2, 1] becomes [1, 10, 2].
- 45
Object integer key insertion order surprise
You added keys '2', '1', '10' to an object expecting insertion order, but they come back as '1', '2', '10' numerically.
- 46
Set stores duplicates due to reference equality
You added two objects with the same content to a Set — they are different references, so both are kept.
- 47
parseFloat stops at first non-numeric character
You called parseFloat on a string with trailing non-numeric text — it silently stops and returns a partial number.
- 48
Array length assignment truncation surprise
You set arr.length = 2 to 'resize' — elements beyond index 1 are silently and permanently removed.
- 49
Modulo of negative number gives negative result
You used % expecting a positive result, but with a negative dividend the result is negative — breaking index wrapping.
- 50
toFixed returns a string, not a number
You did price.toFixed(2) + shipping — toFixed returned a string, so + concatenated instead of adding.
No errors found.