Post

🌋 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

ErrorDescriptionExample
AggregateError: No Promise in Promise.any was resolvedAll 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 recursionCall stack exceeded due to infinite or very deep recursion.function recurse() { recurse(); } recurse();
RangeError: argument is not a valid code pointUnicode code point is out of valid range (0 to 0x10FFFF).String.fromCodePoint(0x110000)
RangeError: BigInt division by zeroDividing a BigInt by zero (0n) is not allowed.10n / 0n
RangeError: BigInt negative exponentBigInt 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 lengthArray length must be a non-negative integer less than 2^32.new Array(-1)
RangeError: invalid dateDate constructor received invalid date string or value.new Date('invalid')
RangeError: precision is out of rangePrecision value outside allowed range in toPrecision().(1.23).toPrecision(500)
RangeError: radix must be an integerRadix for parsing must be an integer between 2 and 36.parseInt('10', 2.5)
RangeError: repeat count must be less than infinityRepeat 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 definedVariable 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 deprecatedOctal 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 identifierUsing reserved words or identifiers as variable/function names.let for = 5;
SyntaxError: \ at end of patternRegex 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 fieldsUsing 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 loopcontinue 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 xFunction 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 nameNamed function missing a name.function () {}
SyntaxError: functions cannot be labelledFunction 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 argumentsGetters cannot have parameters.get x(a) {}
SyntaxError: identifier starts immediately
after numeric literal
No space between number and identifier.let x = 5y;
SyntaxError: illegal characterInvalid 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 expressionQuantifier in regex missing parts./a{2,}/ (if incomplete)
SyntaxError: invalid assignment left-hand sideLeft side of assignment operator invalid.5 = x;
SyntaxError: invalid BigInt syntaxInvalid 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 expressionInvalid property names in Unicode regex escapes./\p{Invalid}/u
SyntaxError: invalid range in character classCharacter class ranges out of order or invalid./[z-a]/
SyntaxError: invalid regexp groupMalformed group in regex./(()/
SyntaxError: invalid regular expression flag “x”Unknown or unsupported regex flags used./a/x
SyntaxError: invalid unicode escape in regular expressionUnicode escape sequences are invalid or malformed./\u{110000}/u
SyntaxError: JSON.parse: bad parsingInvalid JSON string passed to JSON.parse().JSON.parse("{")
SyntaxError: label not foundA break or continue statement references a non-existent label.break missingLabel;
SyntaxError: missing : after property idObject literal missing colon between key and value.let obj = {a 1}
SyntaxError: missing ) after argument listFunction call missing closing parenthesis.foo(bar;
SyntaxError: missing ) after conditionControl statement condition missing closing parenthesis.if (x > 0 {}
SyntaxError: missing ] after element listArray literal missing closing bracket.let arr = [1, 2, 3;
SyntaxError: missing } after function bodyFunction body missing closing brace.function foo() {
SyntaxError: missing } after property listObject literal missing closing brace.let obj = { a: 1, b: 2
SyntaxError: missing = in const declarationconst declaration missing initializer.const x;
SyntaxError: missing formal parameterFunction parameter missing name.function f(,) {}
SyntaxError: missing name after . operatorMember access missing property name.obj..prop
SyntaxError: missing variable nameVariable 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 repeatRegex quantifier applied to nothing./+/
SyntaxError: numbers out of order in {} quantifierQuantifier 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 expectedOperator missing in expression.x 5;
SyntaxError: parameters list has duplicate elementFunction 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 expectedMissing property or method name.class C { get () {} }
SyntaxError: redeclaration of formal parameterFunction parameter redeclared.function f(a, a) {}
SyntaxError: redeclaration of variableVariable declared twice in the same scope.let x; let x;
SyntaxError: return outside functionreturn 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() callSame as above, referencing this before super().constructor() { this.x = 1; super(); }
SyntaxError: Unexpected identifierUnexpected name/token in code syntax.let x = var;
SyntaxError: Unexpected numberUnexpected number found in code.let x = 5 10;
SyntaxError: Unexpected stringUnexpected string literal in code.let x = "hello" "world";
SyntaxError: Unexpected template stringTemplate string used incorrectly.let x = `hello` `world`;
SyntaxError: Unexpected reserved wordReserved word used as identifier.let new = 5;
SyntaxError: Unexpected tokenUnexpected character/token in code.let x = ;
SyntaxError: Unexpected token ILLEGALIllegal 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 literalColon 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 escapeInvalid Unicode escape sequence.let x = "\u{XYZ}";
TypeError: x is not a functionTrying to call a non-function value.let x = 5; x();
TypeError: Cannot read properties of undefined/nullAccessing properties or methods of undefined or null.let x; x.y;
TypeError: Assignment to constant variableAttempting 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 hereUsing super outside class constructor or subclass.super();
URIError: URI malformedMalformed URI string passed to URI functions.decodeURIComponent('%')

JavaScript Warnings (Not always thrown as errors)

WarningDescriptionExample
Duplicate parameter namesUsing the same parameter name more than once in a function declaration.function f(x, x) {}
Implicit global variable assignmentAssigning to undeclared variables creates global variables (in non-strict mode).foo = 10;
Deprecated feature usageUsing outdated or deprecated features (e.g. escape()).escape("Hello")
Octal literals in strict modeUsing legacy octal literals (e.g. 071) is disallowed in strict mode.'use strict'; let x = 071;
Using with statementwith is disallowed in strict mode due to its confusing scoping.'use strict'; with(obj) {}
Non-strict sloppy declarationsVariables 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.