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,136 @@
|
||||
---
|
||||
id: javascript-code-blocks
|
||||
title: "JavaScript Code Blocks"
|
||||
category: "Frontend"
|
||||
status: "draft"
|
||||
verification_status: "conceptual"
|
||||
canonical_id: ""
|
||||
aliases: ["curly braces", "block statement", "standalone block", "block scope", "statement grouping"]
|
||||
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", "code-blocks", "scope", "syntax"]
|
||||
raw_sources: ["https://www.w3schools.com/js/js_codeblocks.asp"]
|
||||
applied_in: []
|
||||
github_commit: ""
|
||||
---
|
||||
|
||||
# [[JavaScript Code Blocks]]
|
||||
|
||||
## 🎯 한 줄 통찰 (One-line insight)
|
||||
A code block is a group of statements wrapped in curly braces `{ }` that are treated as a single unit — and with `let`/`const` it also creates a private scope. [S1]
|
||||
|
||||
## 🧠 핵심 개념 (Core concepts)
|
||||
- **Curly braces group statements** — a code block is one or more statements enclosed in `{ }`, executed together as a unit. [S1]
|
||||
- **Used by language constructs** — functions, `if/else`, `for`, and `while` all use code blocks to hold their body. [S1]
|
||||
- **Blocks define scope** — variables declared with `let` and `const` inside a block are block-scoped and accessible only within that block. [S1]
|
||||
- **Standalone blocks exist** — a `{ }` block can stand on its own (not attached to a function or control statement) purely to create a local scope for `let`/`const` variables. [S1]
|
||||
- **Benefits of blocks** — encapsulation, use of temporary variables, and organized code that avoids name conflicts while staying readable. [S1]
|
||||
|
||||
## 🧩 추출된 패턴 (Extracted patterns)
|
||||
- **Wrap a body in `{ }`** — every function/condition/loop body is a code block. [S1]
|
||||
- **Use a standalone block for a temporary scope** — `{ let x = ...; }` confines short-lived variables and prevents leaks into the surrounding scope. [S1]
|
||||
|
||||
## 📖 세부 내용 (Details)
|
||||
**Curly Braces**
|
||||
JavaScript code blocks are groups of statements enclosed in curly braces `{ }`. They are essential for controlling the flow of execution and for defining variable scope. [S1]
|
||||
|
||||
**Code Blocks and Statements**
|
||||
A code block lets multiple statements be treated as a single unit. Code blocks are required by functions, `if` statements, and loops. [S1]
|
||||
|
||||
A function uses a code block: [S1]
|
||||
```javascript
|
||||
function myFunction() {
|
||||
// This is a code block
|
||||
}
|
||||
```
|
||||
|
||||
An `if...else` statement uses code blocks: [S1]
|
||||
```javascript
|
||||
if (condition) {
|
||||
// This is a code block
|
||||
} else {
|
||||
// This is a code block
|
||||
}
|
||||
```
|
||||
|
||||
A `for` loop uses a code block: [S1]
|
||||
```javascript
|
||||
for (expression 1; expression 2; expression 3) {
|
||||
// This is a code block
|
||||
}
|
||||
```
|
||||
|
||||
A `while` loop uses a code block: [S1]
|
||||
```javascript
|
||||
while (condition) {
|
||||
// This is a code block
|
||||
}
|
||||
```
|
||||
|
||||
**Defining Scope**
|
||||
Variables declared with `let` and `const` inside a code block are block-scoped — they are accessible only within that specific block: [S1]
|
||||
```javascript
|
||||
{
|
||||
let x = 10;
|
||||
// x is accessible here
|
||||
}
|
||||
// x is not accessible here
|
||||
```
|
||||
|
||||
**Standalone Blocks**
|
||||
A code block can exist independently, without being attached to a function or control structure, simply to create a scope for `let` and `const` variables: [S1]
|
||||
```javascript
|
||||
{
|
||||
let x = 10;
|
||||
let y = 100;
|
||||
let areal = x * y;
|
||||
}
|
||||
```
|
||||
Benefits of standalone blocks include encapsulation (variables are confined to the block scope), use of temporary variables, and organized code that prevents name conflicts while maintaining readability. [S1]
|
||||
|
||||
## 🛠️ 적용 사례 (Applied in summary)
|
||||
The page's snippets are the applied cases: bodies of functions, `if/else`, `for`, and `while`, plus a standalone `{ }` block used to scope temporary variables (`x`, `y`, `areal`). No external project/commit applications found in the source.
|
||||
|
||||
## 💻 코드 패턴 (Code patterns)
|
||||
Block-scoped variables (language: JavaScript):
|
||||
```javascript
|
||||
{
|
||||
let x = 10;
|
||||
// x is accessible here
|
||||
}
|
||||
// x is not accessible here
|
||||
```
|
||||
Standalone block as a temporary scope:
|
||||
```javascript
|
||||
{
|
||||
let x = 10;
|
||||
let y = 100;
|
||||
let areal = x * y;
|
||||
}
|
||||
```
|
||||
|
||||
## ⚖️ 모순 및 업데이트 (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 Scope]], [[JavaScript var let const]], [[JavaScript Functions]], [[JavaScript If Else]]
|
||||
- **참조 맥락:** Referenced when explaining how `{ }` both groups statements and confines `let`/`const` variables.
|
||||
|
||||
## 📚 출처 (Sources)
|
||||
- [S1] W3Schools — JavaScript Code Blocks — https://www.w3schools.com/js/js_codeblocks.asp
|
||||
|
||||
## 📝 변경 이력 (Change history)
|
||||
- 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript Code Blocks" page (Astra wiki-curation, P-Reinforce v3.1 format).
|
||||
Reference in New Issue
Block a user