docs(10_Wiki): W3Schools 위키화 — HTML/CSS/JavaScript(core)
W3Schools 튜토리얼을 P-Reinforce v3.1 포맷으로 위키화(영어 본문, 한/영 섹션 헤더). - Topic_HTML: 59문서 (튜토리얼+예제, 레퍼런스/메타 제외) - Topic_CSS: 190문서 (메인 + Advanced/Flexbox/Grid/RWD 전체) - Topic_JavaScript: 120문서 (코어 언어; Temporal/DOM상세/BOM/WebAPI/AJAX/jQuery/Graphics 등은 후속) 각 폴더 00_INDEX.md(MOC) 포함. 코드 verbatim, 미확인분은 "Not found in source" 표기. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,140 @@
|
||||
---
|
||||
id: javascript-silent-errors
|
||||
title: "JavaScript Silent Errors"
|
||||
category: "Frontend"
|
||||
status: "draft"
|
||||
verification_status: "conceptual"
|
||||
canonical_id: ""
|
||||
aliases: ["silent errors", "type coercion", "loose equality", "NaN", "weakly typed"]
|
||||
duplicate_of: ""
|
||||
source_trust_level: "B"
|
||||
confidence_score: 0.86
|
||||
created_at: 2026-06-23
|
||||
updated_at: 2026-06-23
|
||||
review_reason: ""
|
||||
merge_history: []
|
||||
tags: ["javascript", "js", "web", "frontend", "w3schools", "errors", "coercion"]
|
||||
raw_sources: ["https://www.w3schools.com/js/js_errors_silent.asp"]
|
||||
applied_in: []
|
||||
github_commit: ""
|
||||
---
|
||||
|
||||
# [[JavaScript Silent Errors]]
|
||||
|
||||
## 🎯 한 줄 통찰 (One-line insight)
|
||||
Silent errors don't stop execution — JavaScript keeps running while producing wrong results from things like `1/0`, accidental assignment in conditions, failed `parseInt`, and type coercion. [S1]
|
||||
|
||||
## 🧠 핵심 개념 (Core concepts)
|
||||
- **Silent errors won't stop the program** — unlike thrown exceptions, silent errors let execution continue while quietly yielding wrong values. [S1]
|
||||
- **Historical context** — early JavaScript lacked exception handling, contributing to silent-error behavior. [S1]
|
||||
- **Failed numeric operations produce NaN** — many numeric operations that fail produce `NaN` rather than throwing an exception. [S1]
|
||||
- **Type coercion** — JavaScript is weakly typed and automatically converts between data types. [S1]
|
||||
- **String vs numeric coercion** — `+` with any string operand makes everything a string; other arithmetic operators force values to numbers. [S1]
|
||||
- **Loose equality (`==`)** coerces operands, so `5 == "5"` is `true`. [S1]
|
||||
|
||||
## 🧩 추출된 패턴 (Extracted patterns)
|
||||
- **`=` vs `==` trap** — using assignment (`=`) inside an `if` condition silently sets the variable and runs the block instead of comparing. [S1]
|
||||
- **Operator decides the type** — `'5' + '2'` concatenates to `"52"`; `'5' - '2'` subtracts to `3`. The operator, not the operands, dictates coercion. [S1]
|
||||
- **Prefer strict equality and explicit conversion** — use `===`, convert types explicitly, and watch for `NaN` results to avoid silent bugs. [S1]
|
||||
|
||||
## 📖 세부 내용 (Details)
|
||||
**Silent Errors**
|
||||
Silent errors won't stop program execution. Historically, early JavaScript lacked exception handling, which contributed to this behavior. [S1]
|
||||
|
||||
Division by zero does not throw — it yields `Infinity` silently: [S1]
|
||||
```javascript
|
||||
let x = 1 / 0;
|
||||
```
|
||||
|
||||
Accidental assignment inside a condition — the condition uses assignment (`isActive = true`) rather than comparison, setting the variable to true and executing the block: [S1]
|
||||
```javascript
|
||||
let result = "Not Active.";
|
||||
let isActive = false;
|
||||
|
||||
// ❌ Assignment, not comparison
|
||||
if (isActive = true) {
|
||||
let result = "Active!";
|
||||
}
|
||||
```
|
||||
|
||||
Failed parsing produces `NaN`, not an exception. Many numeric operations that fail produce `NaN` (not an exception): [S1]
|
||||
```javascript
|
||||
const result = parseInt("abc");
|
||||
```
|
||||
|
||||
Accessing a missing object property yields `undefined` silently: [S1]
|
||||
```javascript
|
||||
const user = {};
|
||||
let result = user.name;
|
||||
```
|
||||
|
||||
**Type Coercion**
|
||||
JavaScript is weakly typed and automatically converts between data types. [S1]
|
||||
```javascript
|
||||
let result1 = ('5' + '2'); // = 52
|
||||
let result2 = ('5' - '2'); // = 3
|
||||
```
|
||||
|
||||
**String Coercion (+)**
|
||||
If any part of a `+` operation is a string, JavaScript converts everything to strings: [S1]
|
||||
```javascript
|
||||
let x = "5" + 2 // x = "52"
|
||||
```
|
||||
|
||||
**Numeric Coercion**
|
||||
Other operators force values to numbers: [S1]
|
||||
```javascript
|
||||
let x = "5" - 2 // x = 3
|
||||
```
|
||||
|
||||
**Loose Equality (==)**
|
||||
Loose equality coerces operands before comparing: [S1]
|
||||
```javascript
|
||||
let x = (5 == "5") // x = true
|
||||
```
|
||||
|
||||
**Practices to Avoid Bugs**
|
||||
Three recommendations: use strict equality (`===`), be explicit with conversions, and watch for `NaN` results. [S1]
|
||||
|
||||
## 🛠️ 적용 사례 (Applied in summary)
|
||||
The page's snippets demonstrate the silent-error patterns directly — `1/0`, the `=` inside `if`, `parseInt("abc")`, missing properties, and coercion under `+`/`-`/`==`. No external project/commit applications found in the source.
|
||||
|
||||
## 💻 코드 패턴 (Code patterns)
|
||||
Avoid the assignment-in-condition trap and prefer strict equality (language: JavaScript):
|
||||
```javascript
|
||||
// ❌ assignment, always truthy
|
||||
if (isActive = true) { /* ... */ }
|
||||
|
||||
// ✅ strict comparison
|
||||
if (isActive === true) { /* ... */ }
|
||||
```
|
||||
Coercion cheat sheet:
|
||||
```javascript
|
||||
'5' + '2' // "52" (string concatenation)
|
||||
'5' - '2' // 3 (numeric subtraction)
|
||||
"5" + 2 // "52"
|
||||
"5" - 2 // 3
|
||||
5 == "5" // true (loose equality coerces)
|
||||
parseInt("abc") // NaN (no exception thrown)
|
||||
```
|
||||
|
||||
## ⚖️ 모순 및 업데이트 (Contradictions & updates)
|
||||
No contradictions found in the source.
|
||||
|
||||
## ✅ 검증 상태 및 신뢰도
|
||||
- **상태:** draft
|
||||
- **검증 단계:** conceptual (실제 적용 사례 발견 시 applied/validated로 승격 가능)
|
||||
- **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body)
|
||||
- **신뢰 점수:** 0.86
|
||||
- **중복 검사 결과:** 신규 생성 (New discovery)
|
||||
|
||||
## 🔗 지식 그래프 (Knowledge Graph)
|
||||
- **상위/루트:** [[JavaScript Tutorial]]
|
||||
- **관련 개념:** [[JavaScript Errors Intro]], [[JavaScript Error Statements]], [[JavaScript Comparisons]], [[JavaScript Type Conversion]]
|
||||
- **참조 맥락:** Complements the thrown-error pages by covering failures that do not raise exceptions and must be caught by careful coding.
|
||||
|
||||
## 📚 출처 (Sources)
|
||||
- [S1] W3Schools — JavaScript Silent Errors — https://www.w3schools.com/js/js_errors_silent.asp
|
||||
|
||||
## 📝 변경 이력 (Change history)
|
||||
- 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript Silent Errors" page (Astra wiki-curation, P-Reinforce v3.1 format).
|
||||
Reference in New Issue
Block a user