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:
2026-06-23 19:21:18 +09:00
parent 8957890d13
commit 9609c04755
379 changed files with 54618 additions and 6 deletions
@@ -0,0 +1,179 @@
---
id: javascript-array-const
title: "JavaScript Array Const"
category: "Frontend"
status: "draft"
verification_status: "conceptual"
canonical_id: ""
aliases: ["const array", "constant array", "const block scope", "const reassignment", "array const declaration"]
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", "array", "const"]
raw_sources: ["https://www.w3schools.com/js/js_array_const.asp"]
applied_in: []
github_commit: ""
---
# [[JavaScript Array Const]]
## 🎯 한 줄 통찰 (One-line insight)
A `const` array cannot be *reassigned*, but its *elements* can be changed, added, or removed — `const` protects the binding, not the contents. [S1]
## 🧠 핵심 개념 (Core concepts)
- **`const` is common practice for arrays** — ES2015 (ES6) made declaring arrays with `const` standard practice. [S1]
- **A const array cannot be reassigned** — assigning a new array to the same `const` name is an ERROR. [S1]
- **Const array elements CAN change** — you can change, add (`push`), or remove elements of a `const` array. [S1]
- **Const must be assigned when declared** — declaring without assignment is a syntax error. [S1]
- **Const has block scope** — a `const` declared inside a block is not the same variable as one outside the block. [S1]
- **Const cannot be redeclared** — you cannot redeclare or reassign a `const` in the same scope, but you can declare a new `const` with the same name in a different block scope. [S1]
## 🧩 추출된 패턴 (Extracted patterns)
- **Mutate-not-rebind pattern** — use `const` for arrays you will mutate in place (`cars[0] = ...`, `cars.push(...)`) but never reassign. [S1]
- **Block-scoped shadowing** — declare a same-named `const` in a nested block to safely shadow the outer one. [S1]
- **Declare-and-initialize** — always assign a `const` at declaration; deferred assignment is illegal. [S1]
## 📖 세부 내용 (Details)
**Const arrays** — It is a common practice to declare arrays using `const`: [S1]
```javascript
const cars = ["Saab", "Volvo", "BMW"];
```
**Cannot be Reassigned** — an array declared with `const` cannot be reassigned: [S1]
```javascript
const cars = ["Saab", "Volvo", "BMW"];
cars = ["Toyota", "Volvo", "Audi"]; // ERROR
```
**Elements Can be Reassigned** — you can change the elements of a constant array: [S1]
```javascript
// You can create a constant array:
const cars = ["Saab", "Volvo", "BMW"];
// You can change an element:
cars[0] = "Toyota";
// You can add an element:
cars.push("Audi");
```
**Assigned When Declared** — JavaScript `const` variables must be assigned a value when they are declared. This means an array declared with `const` must be initialized when it is declared. Declaring without initializing is a syntax error: [S1]
```javascript
const cars;
cars = ["Saab", "Volvo", "BMW"];
```
This is not how `var` works. With `var`, you can use the variable before it is declared: [S1]
```javascript
cars = ["Saab", "Volvo", "BMW"];
var cars;
```
**Const Block Scope** — a variable declared with `const` has block scope. A `const` declared in a block `{}` is not the same as a variable declared outside the block: [S1]
```javascript
const cars = ["Saab", "Volvo", "BMW"];
// Here cars[0] is "Saab"
{
const cars = ["Toyota", "Volvo", "BMW"];
// Here cars[0] is "Toyota"
}
// Here cars[0] is "Saab"
```
Redeclaring a `var` array with `var`, in another block, in the same program, is allowed and behaves differently (no block scope): [S1]
```javascript
var cars = ["Saab", "Volvo", "BMW"];
// Here cars[0] is "Saab"
{
var cars = ["Toyota", "Volvo", "BMW"];
// Here cars[0] is "Toyota"
}
// Here cars[0] is "Toyota"
```
**Redeclaring Arrays** — Redeclaring a `var` array is allowed anywhere in a program: [S1]
```javascript
var cars = ["Volvo", "BMW"]; // Allowed
var cars = ["Toyota", "BMW"]; // Allowed
cars = ["Volvo", "Saab"]; // Allowed
```
Redeclaring or reassigning an existing `var` or `const` array to `const`, in the same scope or block, is not allowed: [S1]
```javascript
var cars = ["Volvo", "BMW"]; // Allowed
const cars = ["Volvo", "BMW"]; // Not allowed
{
var cars = ["Volvo", "BMW"]; // Allowed
const cars = ["Volvo", "BMW"]; // Not allowed
}
```
Redeclaring or reassigning an existing `const` array, in the same scope or block, is not allowed: [S1]
```javascript
const cars = ["Volvo", "BMW"]; // Allowed
const cars = ["Volvo", "BMW"]; // Not allowed
var cars = ["Volvo", "BMW"]; // Not allowed
cars = ["Volvo", "BMW"]; // Not allowed
{
const cars = ["Volvo", "BMW"]; // Allowed
const cars = ["Volvo", "BMW"]; // Not allowed
var cars = ["Volvo", "BMW"]; // Not allowed
cars = ["Volvo", "BMW"]; // Not allowed
}
```
Redeclaring a `const` array, in another scope or block, is allowed: [S1]
```javascript
const cars = ["Volvo", "BMW"]; // Allowed
{
const cars = ["Volvo", "BMW"]; // Allowed
}
{
const cars = ["Volvo", "BMW"]; // Allowed
}
```
## 🛠️ 적용 사례 (Applied in summary)
The page's own snippets are the canonical applied examples — declaring a `cars` array with `const`, mutating its elements via index assignment and `push`, and demonstrating block-scope shadowing. No external project/commit applications found in the source.
## 💻 코드 패턴 (Code patterns)
Declare and mutate (allowed):
```javascript
const cars = ["Saab", "Volvo", "BMW"];
cars[0] = "Toyota";
cars.push("Audi");
```
Reassign (error):
```javascript
const cars = ["Saab", "Volvo", "BMW"];
cars = ["Toyota", "Volvo", "Audi"]; // ERROR
```
## ⚖️ 비교 및 선택 기준 (Comparison & decision criteria)
- **`const` vs `var` for arrays** — `const` has block scope, must be initialized at declaration, and cannot be reassigned or redeclared in the same scope; `var` lacks block scope, can be used before declaration, and can be freely redeclared. `const` is the recommended common practice. [S1]
## ⚖️ 모순 및 업데이트 (Contradictions & updates)
No contradictions found in the source. The source notes that declaring arrays with `const` became common practice with ES2015 (ES6). [S1]
## ✅ 검증 상태 및 신뢰도
- **상태:** draft
- **검증 단계:** conceptual (실제 적용 사례 발견 시 applied/validated로 승격 가능)
- **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body)
- **신뢰 점수:** 0.89
- **중복 검사 결과:** 신규 생성 (New discovery)
## 🔗 지식 그래프 (Knowledge Graph)
- **상위/루트:** [[JavaScript Tutorial]]
- **관련 개념:** [[JavaScript Arrays]], [[JavaScript Array Iteration]], [[JavaScript Const]]
- **참조 맥락:** Referenced when deciding how to declare arrays and what mutability `const` guarantees.
## 📚 출처 (Sources)
- [S1] W3Schools — JavaScript Array Const — https://www.w3schools.com/js/js_array_const.asp
## 📝 변경 이력 (Change history)
- 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript Array Const" page (Astra wiki-curation, P-Reinforce v3.1 format).