🌋 JavaScript Error and Warning Reference
🌋 JavaScript Error and Warning Reference
When I just started my coding journey, errors felt like my greatest enemy. I was always intimidated by them — every red line on the screen felt like a personal failure, and I often wondered if I was cut out for programming at all. But over time, I realized that errors aren’t enemies; they are my greatest teachers. Every mistake revealed a new lesson, every bug pushed me to think deeper, and every warning guided me toward writing better code.
To learn from errors, you first have to recognize them. This cheatsheet will help you do exactly that.
JavaScript Errors
| Error | Description | Example |
|---|---|---|
| AggregateError: No Promise in Promise.any was resolved | All promises in Promise.any() were rejected, so no promise resolved. | Promise.any([Promise.reject("fail")]) |
| Error: Permission denied to access property “x” | Accessing a restricted or cross-origin property causes this error. | window.parent.location.href (from different origin iframe) |
| InternalError: too much recursion | Call stack exceeded due to infinite or very deep recursion. | function recurse() { recurse(); } recurse(); |
| RangeError: argument is not a valid code point | Unicode code point is out of valid range (0 to 0x10FFFF). | String.fromCodePoint(0x110000) |
| RangeError: BigInt division by zero | Dividing a BigInt by zero (0n) is not allowed. | 10n / 0n |
| RangeError: BigInt negative exponent | BigInt exponentiation does not support negative exponents. | 2n ** -1n |
| RangeError: form must be one of ‘NFC’, ‘NFD’, ‘NFKC’, or ‘NFKD’ | Invalid Unicode normalization form string. | 'abc'.normalize('XYZ') |
| RangeError: invalid array length | Array length must be a non-negative integer less than 2^32. | new Array(-1) |
| RangeError: invalid date | Date constructor received invalid date string or value. | new Date('invalid') |
| RangeError: precision is out of range | Precision value outside allowed range in toPrecision(). | (1.23).toPrecision(500) |
| RangeError: radix must be an integer | Radix for parsing must be an integer between 2 and 36. | parseInt('10', 2.5) |
| RangeError: repeat count must be less than infinity | Repeat count cannot be infinite or too large. | 'a'.repeat(Infinity) |
| RangeError: repeat count mus t be non-negative | Repeat count cannot be negative. | 'a'.repeat(-1) |
| RangeError: x can’t be converted to BigInt because it isn’t an integer | Only integer values can be converted to BigInt. | BigInt(1.5) |
| ReferenceError: “x” is not defined | Variable used before being declared or not declared at all. | console.log(foo); |
| ReferenceError: assignment to undeclared variable “x” | Assigning to a variable not declared in strict mode. | 'use strict'; foo = 123; |
| ReferenceError: can’t access lexical declaration ‘X’ before initialization | Accessing a let or const variable before declaration. | console.log(x); let x = 5; |
| ReferenceError: must call super constructor before using ‘this’ in derived class constructor | this used before super() call in subclass constructor. | constructor() { this.x = 1; super(); } |
| ReferenceError: super() called twice in derived class constructor | Calling super() more than once in a derived class constructor. | constructor() { super(); super(); } |
| SyntaxError: ‘arguments’/’eval’ can’t be defined or assigned to in strict mode code | Cannot use or assign arguments or eval as identifiers in strict mode. | 'use strict'; let arguments = 5; |
| SyntaxError: “0”-prefixed octal literals are deprecated | Octal literals starting with 0 are deprecated and disallowed in strict mode. | let x = 071; |
| SyntaxError: “use strict” not allowed in function with non-simple parameters | Strict mode directive disallowed with complex function parameters. | function f(a = 1) { "use strict"; } |
| SyntaxError: “x” is a reserved identifier | Using reserved words or identifiers as variable/function names. | let for = 5; |
| SyntaxError: \ at end of pattern | Regex pattern ends with unescaped backslash. | /abc\\/ |
| SyntaxError: a declaration in the head of a for-of loop can’t have an initializer | let or const in loop header cannot be initialized. | for (let i = 0 of arr) {} |
| SyntaxError: applying the ‘delete’ operator to an unqualified name is deprecated | Using delete on a variable name is deprecated. | delete x; |
| SyntaxError: arguments is not valid in fields | Using arguments as class field name is invalid. | class C { arguments = 1; } |
| SyntaxError: await is only valid in async functions, async generators and modules | await used outside async function or module. | await fetch('url'); |
| SyntaxError: await/yield expression can’t be used in parameter | Using await or yield in function parameter list is invalid. | function f(await x) {} |
SyntaxError: cannot use ?? unparenthesized within \|\| and && expressions | Nullish coalescing operator requires parentheses when combined with || or &&. | true || false ?? true |
| SyntaxError: character class escape cannot be used in class range in regular expression | Using escape sequences improperly inside regex character ranges. | /[a-\d]/ |
| SyntaxError: continue must be inside loop | continue statement used outside loops. | if (true) { continue; } |
| SyntaxError: duplicate capture group name in regular expression | Regex contains named groups with duplicate names. | /(?'name'a)(?'name'b)/ |
| SyntaxError: duplicate formal argument x | Function parameters declared more than once. | function f(x, x) {} |
| SyntaxError: for-in loop head declarations may not have initializers | Loop variable declaration cannot have initializer. | for (let i = 0 in obj) {} |
| SyntaxError: function statement requires a name | Named function missing a name. | function () {} |
| SyntaxError: functions cannot be labelled | Function declarations cannot have labels. | label: function foo() {} |
| SyntaxError: getter and setter for private name #x should either be both static or non-static | Private getter and setter must both be static or non-static. | class C { static get #x() {}; set #x(v) {} } |
| SyntaxError: getter functions must have no arguments | Getters cannot have parameters. | get x(a) {} |
| SyntaxError: identifier starts immediately after numeric literal | No space between number and identifier. | let x = 5y; |
| SyntaxError: illegal character | Invalid character in source code. | var x = "\u0000"; |
| SyntaxError: import declarations may only appear at top level of a module | import used inside blocks or scripts not marked as modules. | if (true) { import x from 'mod'; } |
| SyntaxError: incomplete quantifier in regular expression | Quantifier in regex missing parts. | /a{2,}/ (if incomplete) |
| SyntaxError: invalid assignment left-hand side | Left side of assignment operator invalid. | 5 = x; |
| SyntaxError: invalid BigInt syntax | Invalid format for BigInt literal. | 123n4 |
| SyntaxError: invalid capture group name in regular expression | Regex named capture group has invalid name. | /(?<1name>a)/ |
| SyntaxError: invalid character in class in regular expression | Invalid characters inside regex character class. | /[a-]/ |
| SyntaxError: invalid class set operation in regular expression | Invalid use of set operations like subtraction in regex classes. | /[a-z&&[^aeiou]]/ (unsupported) |
| SyntaxError: invalid decimal escape in regular expression | Invalid decimal escapes in regex. | /\9/ |
| SyntaxError: invalid identity escape in regular expression | Invalid escape sequences in regex. | /\c/ |
| SyntaxError: invalid named capture reference in regular expression | Reference to undefined named group in regex. | /\k<name>/ without group named name |
| SyntaxError: invalid property name in regular expression | Invalid property names in Unicode regex escapes. | /\p{Invalid}/u |
| SyntaxError: invalid range in character class | Character class ranges out of order or invalid. | /[z-a]/ |
| SyntaxError: invalid regexp group | Malformed group in regex. | /(()/ |
| SyntaxError: invalid regular expression flag “x” | Unknown or unsupported regex flags used. | /a/x |
| SyntaxError: invalid unicode escape in regular expression | Unicode escape sequences are invalid or malformed. | /\u{110000}/u |
| SyntaxError: JSON.parse: bad parsing | Invalid JSON string passed to JSON.parse(). | JSON.parse("{") |
| SyntaxError: label not found | A break or continue statement references a non-existent label. | break missingLabel; |
| SyntaxError: missing : after property id | Object literal missing colon between key and value. | let obj = {a 1} |
| SyntaxError: missing ) after argument list | Function call missing closing parenthesis. | foo(bar; |
| SyntaxError: missing ) after condition | Control statement condition missing closing parenthesis. | if (x > 0 {} |
| SyntaxError: missing ] after element list | Array literal missing closing bracket. | let arr = [1, 2, 3; |
| SyntaxError: missing } after function body | Function body missing closing brace. | function foo() { |
| SyntaxError: missing } after property list | Object literal missing closing brace. | let obj = { a: 1, b: 2 |
| SyntaxError: missing = in const declaration | const declaration missing initializer. | const x; |
| SyntaxError: missing formal parameter | Function parameter missing name. | function f(,) {} |
| SyntaxError: missing name after . operator | Member access missing property name. | obj..prop |
| SyntaxError: missing variable name | Variable declaration missing identifier. | let ; |
| SyntaxError: negated character class with strings in regular expression | Negated character class contains string instead of characters. | /[^abc]+/ with invalid usage |
| SyntaxError: new keyword cannot be used with an optional chain | Cannot use new with optional chaining operator ?.. | new obj?.method(); |
| SyntaxError: nothing to repeat | Regex quantifier applied to nothing. | /+/ |
| SyntaxError: numbers out of order in {} quantifier | Quantifier range with min greater than max. | /a{5,2}/ |
| SyntaxError: object destructuring requires an assignment target | Destructuring must be part of assignment or declaration. | ({a, b}); alone |
| SyntaxError: operator expected | Operator missing in expression. | x 5; |
| SyntaxError: parameters list has duplicate element | Function parameters duplicated. | function f(x, x) {} |
| SyntaxError: private field ‘#x’ must be declared in an enclosing class | Private class field used without declaration in class. | this.#x without #x declaration |
| SyntaxError: private field ‘#x’ must be declared in an enclosing class | Private field access on wrong class or without declaration. | other.#x |
| SyntaxError: property or method expected | Missing property or method name. | class C { get () {} } |
| SyntaxError: redeclaration of formal parameter | Function parameter redeclared. | function f(a, a) {} |
| SyntaxError: redeclaration of variable | Variable declared twice in the same scope. | let x; let x; |
| SyntaxError: return outside function | return used outside function body. | return 5; at top-level code |
| SyntaxError: script or module missing semicolon before function declaration | Semicolon missing before function declaration causes parse error. | let a = 1 function f() {} |
| SyntaxError: strict mode code may not include a with statement | with is disallowed in strict mode. | 'use strict'; with(obj) {} |
| SyntaxError: super() must be called before accessing ‘this’ in constructor | Calling this before super() in subclass constructor. | constructor() { this.x; super(); } |
| SyntaxError: this is not allowed before super() call | Same as above, referencing this before super(). | constructor() { this.x = 1; super(); } |
| SyntaxError: Unexpected identifier | Unexpected name/token in code syntax. | let x = var; |
| SyntaxError: Unexpected number | Unexpected number found in code. | let x = 5 10; |
| SyntaxError: Unexpected string | Unexpected string literal in code. | let x = "hello" "world"; |
| SyntaxError: Unexpected template string | Template string used incorrectly. | let x = `hello` `world`; |
| SyntaxError: Unexpected reserved word | Reserved word used as identifier. | let new = 5; |
| SyntaxError: Unexpected token | Unexpected character/token in code. | let x = ; |
| SyntaxError: Unexpected token ILLEGAL | Illegal character in code. | let x = "\u0000"; |
| SyntaxError: Unexpected token, expected “]” | Closing bracket ] expected but not found. | let arr = [1, 2; |
| SyntaxError: Unexpected token, expected “)” | Closing parenthesis ) expected but missing. | foo(bar; |
| SyntaxError: Unexpected token, expected “:” in object literal | Colon missing in object literal key-value pair. | let obj = {a 1} |
| SyntaxError: Unexpected token, expected “;” | Semicolon missing or unexpected token found. | let x = 5 let y = 10; |
| SyntaxError: Unexpected Unicode escape | Invalid Unicode escape sequence. | let x = "\u{XYZ}"; |
| TypeError: x is not a function | Trying to call a non-function value. | let x = 5; x(); |
| TypeError: Cannot read properties of undefined/null | Accessing properties or methods of undefined or null. | let x; x.y; |
| TypeError: Assignment to constant variable | Attempting to reassign a constant variable declared with const. | const x = 5; x = 10; |
| TypeError: Invalid assignment to const ‘x’ | Another form of reassignment error for const. | const x = 3; x = 4; |
| TypeError: ‘super’ keyword unexpected here | Using super outside class constructor or subclass. | super(); |
| URIError: URI malformed | Malformed URI string passed to URI functions. | decodeURIComponent('%') |
JavaScript Warnings (Not always thrown as errors)
| Warning | Description | Example |
|---|---|---|
| Duplicate parameter names | Using the same parameter name more than once in a function declaration. | function f(x, x) {} |
| Implicit global variable assignment | Assigning to undeclared variables creates global variables (in non-strict mode). | foo = 10; |
| Deprecated feature usage | Using outdated or deprecated features (e.g. escape()). | escape("Hello") |
| Octal literals in strict mode | Using legacy octal literals (e.g. 071) is disallowed in strict mode. | 'use strict'; let x = 071; |
Using with statement | with is disallowed in strict mode due to its confusing scoping. | 'use strict'; with(obj) {} |
| Non-strict sloppy declarations | Variables declared without var, let, or const in non-strict mode. | x = 1; |
Using deprecated __proto__ | Directly accessing or assigning __proto__ is discouraged. | obj.__proto__ = null; |
This post is licensed under CC BY 4.0 by the author.