---
id: javascript-conditional-operators
title: "JavaScript Conditional Operators"
category: "Frontend"
status: "draft"
verification_status: "conceptual"
canonical_id: ""
aliases: ["JS conditional statements", "conditional statements", "ternary operator", "if else switch overview", "control flow", "decision statements"]
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", "conditionals", "control-flow"]
raw_sources: ["https://www.w3schools.com/js/js_conditionals.asp"]
applied_in: []
github_commit: ""
---

# [[JavaScript Conditional Operators]]

## 🎯 한 줄 통찰 (One-line insight)
Conditional statements run different code depending on `true`/`false` conditions — JavaScript provides `if`, `else`, `else if`, `switch`, and the ternary `(? :)` shorthand. [S1]

## 🧠 핵심 개념 (Core concepts)
- **Conditional statements branch on conditions** — they let you perform different actions for different conditions. [S1]
- **`if`** — use `if` to specify a code block to be executed if a specified condition is `true`. [S1]
- **`else`** — use `else` to specify a code block to be executed if the same condition is `false`. [S1]
- **`else if`** — use `else if` to specify a new condition to test if the first condition is `false`. [S1]
- **`switch`** — use `switch` to specify many alternative code blocks to be executed. [S1]
- **Ternary `(? :)`** — use `(? :)` (ternary) as a shorthand for `if...else`. [S1]

## 🧩 추출된 패턴 (Extracted patterns)
- **Pick the right branching construct** — single decision → `if`/`else`; chained conditions → `else if`; many discrete cases → `switch`; one-line value choice → ternary. [S1]
- **Ternary as expression** — the ternary form `condition ? expression1 : expression2` returns a value, unlike statement-only `if`. [S1]

## 📖 세부 내용 (Details)
**Conditional Statements** [S1]
Conditional statements allow you to perform different actions for different conditions — running different code depending on `true` or `false` conditions. Conditional statements include:
- **if** — Use `if` to specify a code block to be executed, if a specified condition is `true`.
- **else** — Use `else` to specify a code block to be executed, if the same condition is `false`.
- **else if** — Use `else if` to specify a new condition to test, if the first condition is `false`.
- **switch** — Use `switch` to specify many alternative code blocks to be executed.
- **ternary (? :)** — Use `(? :)` (ternary) as a shorthand for `if...else`.

**Ternary (? :) syntax** [S1]
The page shows the ternary as a syntax template rather than a runnable named example:
```javascript
condition ? expression1 : expression2
```

This page is an overview/index of the conditional constructs; the detailed runnable examples live on the dedicated pages it links to. A concrete named-variable ternary example was Not found in source on this page.

## 🛠️ 적용 사례 (Applied in summary)
This is an overview page; it points to the dedicated `if`, `else`, `switch`, and ternary pages where the working examples reside. No external project/commit applications found in the source.

## 💻 코드 패턴 (Code patterns)
Ternary shorthand for `if...else`:
```javascript
condition ? expression1 : expression2
```

## ⚖️ 모순 및 업데이트 (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 If]], [[JavaScript If Else]], [[JavaScript Comparisons]], [[JavaScript Operators]]
- **참조 맥락:** The entry point for control-flow branching, referenced before choosing `if`/`else`/`switch`/ternary.

## 📚 출처 (Sources)
- [S1] W3Schools — JavaScript Conditional Operators — https://www.w3schools.com/js/js_conditionals.asp

## 📝 변경 이력 (Change history)
- 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript Conditional Operators" page (Astra wiki-curation, P-Reinforce v3.1 format).
