--- 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).