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,125 @@
|
||||
---
|
||||
id: javascript-logical-operators
|
||||
title: "JavaScript Logical Operators"
|
||||
category: "Frontend"
|
||||
status: "draft"
|
||||
verification_status: "conceptual"
|
||||
canonical_id: ""
|
||||
aliases: ["logical operators", "AND OR NOT", "&& || !", "nullish coalescing", "JS logic"]
|
||||
duplicate_of: ""
|
||||
source_trust_level: "B"
|
||||
confidence_score: 0.89
|
||||
created_at: 2026-06-23
|
||||
updated_at: 2026-06-23
|
||||
review_reason: ""
|
||||
merge_history: []
|
||||
tags: ["javascript", "js", "web", "frontend", "w3schools", "logical-operators", "nullish-coalescing", "operators"]
|
||||
raw_sources: ["https://www.w3schools.com/js/js_logical.asp"]
|
||||
applied_in: []
|
||||
github_commit: ""
|
||||
---
|
||||
|
||||
# [[JavaScript Logical Operators]]
|
||||
|
||||
## 🎯 한 줄 통찰 (One-line insight)
|
||||
Logical operators (`&&`, `||`, `!`) combine boolean expressions into more complex logic, while `??` returns a fallback only when the left operand is nullish (`null` or `undefined`). [S1]
|
||||
|
||||
## 🧠 핵심 개념 (Core concepts)
|
||||
- **Combine boolean expressions** — logical operators are used to combine boolean expressions and to modify the results of comparisons. [S1]
|
||||
- **`&&` (AND)** — true only when both operands are true. [S1]
|
||||
- **`||` (OR)** — true when at least one operand is true. [S1]
|
||||
- **`!` (NOT)** — inverts a boolean result. [S1]
|
||||
- **`??` (Nullish coalescing)** — returns the right operand when the left operand is nullish (`null` or `undefined`); otherwise returns the left operand. [S1]
|
||||
- **Nullish ≠ falsy** — `??` checks specifically for `null`/`undefined`, so values like `0`, `""`, and `false` are preserved. [S1]
|
||||
|
||||
## 🧩 추출된 패턴 (Extracted patterns)
|
||||
- **Condition + combinator** — use a comparison operator to check a condition and a logical operator to combine conditions into more complex logic. [S1]
|
||||
- **Nullish-safe default** — use `??` when an empty string or `false` is an acceptable value and only `null`/`undefined` should trigger the fallback. [S1]
|
||||
|
||||
## 📖 세부 내용 (Details)
|
||||
**Logical operators** [S1]
|
||||
Logical operators are used to combine boolean expressions. Logical operators can be used to modify the results of comparisons. Typically, you will use a comparison operator to check a condition, and a logical operator to combine conditions into more complex logic. Logical operators are used to determine the logic between variables or values.
|
||||
|
||||
Given `x = 6` and `y = 3`:
|
||||
|
||||
| Operator | Name | Example |
|
||||
|----------|------|---------|
|
||||
| && | AND | (x < 10 && y > 1) is true |
|
||||
| \|\| | OR | (x === 5 \|\| y === 5) is false |
|
||||
| ! | NOT | !(x === y) is true |
|
||||
|
||||
**AND (`&&`) example** [S1]
|
||||
```javascript
|
||||
let x = 6;
|
||||
let y = 3;
|
||||
let z = (x < 10 && y > 1)
|
||||
```
|
||||
|
||||
**OR (`||`) example** [S1]
|
||||
```javascript
|
||||
let x = 6;
|
||||
let y = -3;
|
||||
let z = (x > 0 || y > 0)
|
||||
```
|
||||
|
||||
**NOT (`!`) example** [S1]
|
||||
```javascript
|
||||
let x = (5 == 8);
|
||||
let y = !(5 == 8)
|
||||
```
|
||||
|
||||
**The Nullish Coalescing Operator (`??`)** [S1]
|
||||
The `??` operator returns the right operand when the left operand is nullish (`null` or `undefined`), otherwise it returns the left operand.
|
||||
```javascript
|
||||
let name = null;
|
||||
let text = "missing";
|
||||
let result = name ?? text;
|
||||
```
|
||||
When programming, a lot of values can be falsy (like `0`, empty strings, `false`, `undefined`, `null`, `NaN`). However, sometimes you want to check if a variable is nullish (either `undefined` or `null`), like when it is okay for a variable to be an empty string or a false value. Then you can use the nullish coalescing operator.
|
||||
|
||||
**Browser support** [S1]
|
||||
`??` is an ES2020 feature. ES2020 is fully supported in all modern browsers since September 2020 (Chrome 85, Edge 85, Firefox 79, Safari 14, Opera 71).
|
||||
|
||||
## 🛠️ 적용 사례 (Applied in summary)
|
||||
The page's own snippets are the canonical applied examples — combining comparisons with `&&` and `||`, negating with `!`, and supplying a nullish-safe default with `??`. No external project/commit applications found in the source.
|
||||
|
||||
## 💻 코드 패턴 (Code patterns)
|
||||
Combine conditions with AND / OR:
|
||||
```javascript
|
||||
let z = (x < 10 && y > 1)
|
||||
let w = (x > 0 || y > 0)
|
||||
```
|
||||
Negate a result:
|
||||
```javascript
|
||||
let y = !(5 == 8)
|
||||
```
|
||||
Nullish-safe default:
|
||||
```javascript
|
||||
let name = null;
|
||||
let text = "missing";
|
||||
let result = name ?? text;
|
||||
```
|
||||
|
||||
## ⚖️ 비교 및 선택 기준 (Comparison & decision criteria)
|
||||
- **`??` vs `||` for defaults** — `||` falls back on any falsy value (`0`, `""`, `false`, `null`, `undefined`, `NaN`), whereas `??` falls back only on nullish values (`null`/`undefined`). Choose `??` when an empty string or `false` is a valid value that should be preserved. [S1]
|
||||
|
||||
## ⚖️ 모순 및 업데이트 (Contradictions & updates)
|
||||
No contradictions found in the source. The `??` operator is noted as an ES2020 addition relative to the older `&&`/`||`/`!` operators.
|
||||
|
||||
## ✅ 검증 상태 및 신뢰도
|
||||
- **상태:** draft
|
||||
- **검증 단계:** conceptual (실제 적용 사례 발견 시 applied/validated로 승격 가능)
|
||||
- **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body)
|
||||
- **신뢰 점수:** 0.89
|
||||
- **중복 검사 결과:** 신규 생성 (New discovery)
|
||||
|
||||
## 🔗 지식 그래프 (Knowledge Graph)
|
||||
- **상위/루트:** [[JavaScript Tutorial]]
|
||||
- **관련 개념:** [[JavaScript Booleans]], [[JavaScript Comparisons]], [[JavaScript If Else]], [[JavaScript Ternary]]
|
||||
- **참조 맥락:** Used to build compound conditions in `if`/`while`/ternary expressions and to supply safe default values.
|
||||
|
||||
## 📚 출처 (Sources)
|
||||
- [S1] W3Schools — JavaScript Logical Operators — https://www.w3schools.com/js/js_logical.asp
|
||||
|
||||
## 📝 변경 이력 (Change history)
|
||||
- 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript Logical Operators" page (Astra wiki-curation, P-Reinforce v3.1 format).
|
||||
Reference in New Issue
Block a user