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>
7.0 KiB
id, title, category, status, verification_status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, created_at, updated_at, review_reason, merge_history, tags, raw_sources, applied_in, github_commit
| id | title | category | status | verification_status | canonical_id | aliases | duplicate_of | source_trust_level | confidence_score | created_at | updated_at | review_reason | merge_history | tags | raw_sources | applied_in | github_commit | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| javascript-array-const | JavaScript Array Const | Frontend | draft | conceptual |
|
B | 0.89 | 2026-06-23 | 2026-06-23 |
|
|
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)
constis common practice for arrays — ES2015 (ES6) made declaring arrays withconststandard practice. [S1]- A const array cannot be reassigned — assigning a new array to the same
constname is an ERROR. [S1] - Const array elements CAN change — you can change, add (
push), or remove elements of aconstarray. [S1] - Const must be assigned when declared — declaring without assignment is a syntax error. [S1]
- Const has block scope — a
constdeclared inside a block is not the same variable as one outside the block. [S1] - Const cannot be redeclared — you cannot redeclare or reassign a
constin the same scope, but you can declare a newconstwith the same name in a different block scope. [S1]
🧩 추출된 패턴 (Extracted patterns)
- Mutate-not-rebind pattern — use
constfor arrays you will mutate in place (cars[0] = ...,cars.push(...)) but never reassign. [S1] - Block-scoped shadowing — declare a same-named
constin a nested block to safely shadow the outer one. [S1] - Declare-and-initialize — always assign a
constat declaration; deferred assignment is illegal. [S1]
📖 세부 내용 (Details)
Const arrays — It is a common practice to declare arrays using const: [S1]
const cars = ["Saab", "Volvo", "BMW"];
Cannot be Reassigned — an array declared with const cannot be reassigned: [S1]
const cars = ["Saab", "Volvo", "BMW"];
cars = ["Toyota", "Volvo", "Audi"]; // ERROR
Elements Can be Reassigned — you can change the elements of a constant array: [S1]
// 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]
const cars;
cars = ["Saab", "Volvo", "BMW"];
This is not how var works. With var, you can use the variable before it is declared: [S1]
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]
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]
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]
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]
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]
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]
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):
const cars = ["Saab", "Volvo", "BMW"];
cars[0] = "Toyota";
cars.push("Audi");
Reassign (error):
const cars = ["Saab", "Volvo", "BMW"];
cars = ["Toyota", "Volvo", "Audi"]; // ERROR
⚖️ 비교 및 선택 기준 (Comparison & decision criteria)
constvsvarfor arrays —consthas block scope, must be initialized at declaration, and cannot be reassigned or redeclared in the same scope;varlacks block scope, can be used before declaration, and can be freely redeclared.constis 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
constguarantees.
📚 출처 (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).