--- id: javascript-errors-intro title: "JavaScript Errors Intro" category: "Frontend" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["JavaScript errors", "try catch throw", "ReferenceError", "TypeError", "RangeError", "error handling"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.88 created_at: 2026-06-23 updated_at: 2026-06-23 review_reason: "" merge_history: [] tags: ["javascript", "js", "web", "frontend", "w3schools", "errors", "try-catch"] raw_sources: ["https://www.w3schools.com/js/js_errors_intro.asp"] applied_in: [] github_commit: "" --- # [[JavaScript Errors Intro]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) Errors will happen in running JavaScript code; `try` tests a block for runtime errors and `catch` handles them via an error object whose `name` identifies the error type. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Errors will happen** β€” many error types can occur during execution: Reference Errors, Type Errors, Range Errors, URI Errors, Syntax Errors, and Eval Errors. [S1] - **try / catch** β€” the `try` statement tests a block of code for errors during execution; the `catch` statement handles the error if one occurs. [S1] - **The error object** β€” the `catch` block receives an error object; `err.name` returns the type of error. [S1] - **Syntax errors are special** β€” a `SyntaxError` happens before runtime, so it is not catchable by ordinary `try...catch`. [S1] - **EvalError is legacy** β€” newer JavaScript versions raise `SyntaxError` instead of `EvalError`. [S1] ## 🧩 μΆ”μΆœλœ νŒ¨ν„΄ (Extracted patterns) - **Wrap risky code, inspect `err.name`** β€” put the operation that may fail inside `try`, then read `err.name` in `catch` to discover which error type occurred. [S1] - **Trigger by error category** β€” each error type is provoked by a distinct kind of mistake: undefined references β†’ `ReferenceError`; wrong-type operations β†’ `TypeError`; out-of-range values β†’ `RangeError`; illegal URI characters β†’ `URIError`. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) **Errors Will Happen!** While executing JavaScript code, different errors can occur, including Reference Errors, Type Errors, Range Errors, URI Errors, Syntax Errors, and Eval Errors. [S1] **How to Handle JavaScript Errors** The `try` statement tests a block of code for errors during execution, while `catch` handles errors if they occur. [S1] **Reference Errors** A `ReferenceError` occurs when referencing a variable that doesn't exist or accessing a variable before initialization. [S1] Using a non-existing variable: [S1] ```javascript let x = 5; try { x = y + 1; } catch(err) { let text = err.name; } ``` Accessing a variable before initialization: [S1] ```javascript try { let x = y; let y = 5; } catch(err) { let text = err.name; } ``` **JavaScript Type Errors** A `TypeError` occurs when a value is the wrong type or an operation is invalid on that type. [S1] Calling a non-function: [S1] ```javascript let anna = 5; try { anna(5); } catch(err) { let text = err.name; } ``` Invalid method on a number: [S1] ```javascript let num = 1; try { num.toUpperCase(); } catch(err) { let text = err.name; } ``` **JavaScript Range Errors** A `RangeError` occurs when a value falls outside its valid range. [S1] Invalid array length: [S1] ```javascript try { new Array(-1); } catch(err) { let text = err.name; } ``` Invalid precision argument: [S1] ```javascript let num = 1; try { num.toPrecision(500); } catch(err) { let text = err.name; } ``` **JavaScript URI Errors** A `URIError` occurs with illegal characters in URI functions. [S1] ```javascript try { decodeURI("%%%"); } catch(err) { document.getElementById("demo").innerHTML = err.name; } ``` **JavaScript Syntax Errors** A `SyntaxError` occurs when code violates JavaScript grammar rules. Syntax errors are not catchable by `try...catch` because they happen before runtime. [S1] ```javascript try { let x = Math.round(4.6;) } catch(err) { let text = err.name + " " + err.description; } ``` **JavaScript Eval Error** An `EvalError` indicates an error in the `eval()` function. Newer JavaScript versions use `SyntaxError` instead. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) The page's own snippets are the canonical applied examples β€” each wraps a deliberate mistake in `try` and reads `err.name` in `catch` to surface the resulting error type. No external project/commit applications found in the source. ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Wrap risky code and inspect the error type (language: JavaScript): ```javascript try { // code that may throw } catch(err) { let text = err.name; } ``` Provoke each error category: ```javascript x = y + 1; // ReferenceError (y not defined) anna(5); // TypeError (anna is not a function) new Array(-1); // RangeError (invalid array length) decodeURI("%%%"); // URIError (illegal URI characters) ``` ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) - **EvalError deprecation** β€” the source notes that newer JavaScript versions raise `SyntaxError` instead of `EvalError`, so `EvalError` is effectively legacy. [S1] ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual (μ‹€μ œ 적용 사둀 발견 μ‹œ applied/validated둜 승격 κ°€λŠ₯) - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.88 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[JavaScript Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[JavaScript Silent Errors]], [[JavaScript Error Statements]], [[JavaScript Error Object]], [[JavaScript Debugging]] - **μ°Έμ‘° λ§₯락:** The starting point for understanding which JavaScript error types exist and how `try...catch` surfaces them. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” JavaScript Errors Intro β€” https://www.w3schools.com/js/js_errors_intro.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript Errors Intro" page (Astra wiki-curation, P-Reinforce v3.1 format).