JavaScript Error Types and Exception Classification
Quick answer
Standard Error subclasses describe different kinds of failures. Choosing a relevant type makes a caller’s recovery policy more precise.
How it works
TypeError often indicates an inappropriate value or operation; RangeError indicates a value outside a permitted range; ReferenceError describes unresolved or uninitialized bindings; SyntaxError describes invalid syntax or parsing failures. URIError relates to malformed URI encoding or decoding. AggregateError groups several errors. EvalError exists largely for historical compatibility; it is not the general error for dynamic evaluation.
try { (42).toFixed(101); } catch (error) { console.log(error.name); }Expected output in Node.js:
RangeErrorThe requested number of digits is outside the allowed range.
try { null.price; } catch (error) { console.log(error instanceof TypeError, error instanceof Error); }Expected output in Node.js:
true trueNull property access produces a TypeError, which is also an Error in this realm.
Common mistakes
Do not infer exact failure type solely from the message. Runtime messages can differ; classify using type or documented codes where available.
Practice
Classify sample failure conditions by error kind without depending on runtime-specific message text.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
JavaScript Error Types and Exception Classification — Knowledge Check
Apply the taught concept and predict the output.
Which error type is appropriate for a numeric argument outside an explicitly allowed range?
Which error typically describes an uninitialized lexical binding access?
Which standard Error subtype groups multiple failures?
What is the exact console output in JavaScript Error Types and Exception Classification example 1?
try { (42).toFixed(101); } catch (error) { console.log(error.name); }What is the exact console output in JavaScript Error Types and Exception Classification example 2?
try { null.price; } catch (error) { console.log(error instanceof TypeError, error instanceof Error); }