Files
2nd/10_Wiki/Topic_Programming/Topic_JavaScript/JavaScript_Let.md
T
Antigravity Agent e9cbf23ab5 docs(10_Wiki): Dev 폴더 누락분 반영 — Topic_Programming으로 통합
이전 재구성 작업에서 Dev/ 폴더가 누락되었던 것을 반영.

- Dev/Topic_Programming(중첩 폴더, 78개)은 Dev 자체 최상위 폴더들
  (Architecture/Conventions/Engineering_Intelligence 등)과 완전 중복이라 제거.
- Dev 최상위 엔지니어링 지식 폴더(Architecture/Conventions/Engineering_Intelligence/
  Failure_Library/Generalized_Principles/Language/Pattern_Catalog/Platform_Guides/
  Subsystems, 77개)는 이미 Topic_Programming/Topic_Programming에 더 최신 버전이
  존재해 중복 제거(고유 콘텐츠 1개는 예외 처리하여 이동 보존).
- Dev의 W3Schools 언어 튜토리얼 폴더(Topic_C/CPP/CSS/CSharp/HOWTO/HTML/Java/
  JavaScript/PHP/Python/SQL/W3CSS, 1201개)는 전부 Topic_Programming 하위로 이동.
- 에이전트 운영 상태(.astra/docs)는 그대로 유지, 콘텐츠 폴더만 정리.
- Topic_Programming 최종 문서 수: 2784 → 3985.
2026-07-05 00:39:13 +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).