Files
2nd/10_Wiki/Topic_JavaScript/JavaScript_Let.md
T
koriweb 9609c04755 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>
2026-06-23 19:21:18 +09:00

6.7 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-let JavaScript Let Frontend draft conceptual
let keyword
block scope
let vs var
let hoisting
ES6 let
B 0.88 2026-06-23 2026-06-23
javascript
js
web
frontend
w3schools
let
block-scope
https://www.w3schools.com/js/js_let.asp

JavaScript Let

🎯 한 줄 통찰 (One-line insight)

The let keyword (ES6, 2015) introduced block scope to JavaScript — let variables are confined to their { } block, cannot be redeclared in the same scope, and are hoisted but not initialized. [S1]

🧠 핵심 개념 (Core concepts)

  • Block scope (new in ES6) — before ES6 (2015) JavaScript had no block scope; variables declared with let inside a { } block cannot be accessed outside it. [S1]
  • Function scope — variables declared with var, let, or const inside a function cannot be accessed outside it. [S1]
  • var is global/function scoped — a var declared inside a block can still be used outside the block. [S1]
  • Cannot be redeclared in the same scopelet variables cannot be redeclared in the same scope (whereas var can). [S1]
  • Hoisted but not initializedlet variables are hoisted to the top of their block but not initialized; using one before its declaration causes a ReferenceError. [S1]

🧩 추출된 패턴 (Extracted patterns)

  • Block-local shadowing — declaring let x inside a block shadows an outer x without altering it, unlike var which leaks back out. [S1]
  • Redeclare across different blocks — the same let name may be redeclared in different blocks, just not twice in the same scope. [S1]
  • Declare-before-use discipline — because let is not initialized when hoisted, always declare before using. [S1]

📖 세부 내용 (Details)

Block Scope — Before ES6 (2015), JavaScript had only Global Scope and Function Scope. ES6 introduced two new JavaScript keywords: let and const. These two keywords provided Block Scope in JavaScript. Variables declared inside a { } block cannot be accessed from outside the block: [S1]

{
  let x = 2;
}
// x can NOT be used here

Function Scope — Variables declared with var, let, and const are quite similar when declared inside a function — they all have Function Scope: [S1]

function myfunction() {
  var x = 1;
  let y = 2;
  const z = 3;
}
//x can NOT be used here
//y can NOT be used here
//z can NOT be used here

Global Scope (var) — Variables declared with var inside a block can be accessed from outside the block: [S1]

{
  var x = 2;
}
// x CAN be used here

Cannot be Redeclared — Variables defined with let can not be redeclared. You can not accidentally redeclare a variable declared with let: [S1]

let x = "John Doe";
let x = 0;  // Error

Variables defined with var can be redeclared: [S1]

var x = "John Doe";
var x = 0;  // Allowed

Redeclaring Variables — Redeclaring a variable using the var keyword can impose problems. Redeclaring a variable inside a block will also redeclare the variable outside the block: [S1]

var x = 10;
// Here x is 10

{
  var x = 2;
  // Here x is 2
}

// Here x is 2

Redeclaring a variable using the let keyword can solve this problem. Redeclaring a variable inside a block will not redeclare the variable outside the block: [S1]

let x = 10;
// Here x is 10

{
  let x = 2;
  // Here x is 2
}

// Here x is 10

Redeclaring (across different blocks) — Redeclaring a let variable in different blocks is allowed: [S1]

let x = 2;   // Allowed

{
  let x = 3;   // Allowed
}

{
  let x = 4;    // Allowed
}

Let Hoisting — Variables defined with let are hoisted to the top of the block, but not initialized. Using a let variable before it is declared will result in a ReferenceError: [S1]

carName = "Saab";
let carName = "Volvo";  // ReferenceError

By contrast, variables defined with var are hoisted to the top and can be used before declaration: [S1]

carName = "Volvo";
var carName;  // OK

🛠️ 적용 사례 (Applied in summary)

The page's own snippets are the canonical applied examples — block-scoped let x, the var-leaks vs let-contained redeclaration pair, redeclaring let across separate blocks, and the hoisting ReferenceError contrast. No external project/commit applications found in the source.

💻 코드 패턴 (Code patterns)

Block-scoped variable:

{
  let x = 2;
}
// x can NOT be used here

Safe shadowing:

let x = 10;
{
  let x = 2;
}
// Here x is 10

⚖️ 비교 및 선택 기준 (Comparison & decision criteria)

The source compares the three declaration keywords: [S1]

Feature var let const
Scope Function or global Block-scope { } Block-scope { }
Reassignment Can be updated Can be updated Cannot be updated
Redeclaration Can be redeclared Cannot be redeclared Cannot be redeclared
Hoisting Initialized as undefined Hoisted, not initialized Hoisted, not initialized

Choose let when you need a reassignable variable scoped to a block; choose const when the value will not change; avoid var to prevent unintentional global/function-scope leakage. [S1]

⚖️ 모순 및 업데이트 (Contradictions & updates)

No contradictions found in the source. (The page frames let/const as a 2015 update over the older var-only model — an evolution, not a contradiction.)

검증 상태 및 신뢰도

  • 상태: draft
  • 검증 단계: conceptual (실제 적용 사례 발견 시 applied/validated로 승격 가능)
  • 출처 신뢰도: B (W3Schools — widely used educational reference, not a primary standards body)
  • 신뢰 점수: 0.88
  • 중복 검사 결과: 신규 생성 (New discovery)

🔗 지식 그래프 (Knowledge Graph)

📚 출처 (Sources)

📝 변경 이력 (Change history)

  • 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript Let" page (Astra wiki-curation, P-Reinforce v3.1 format).