--- id: javascript-let title: "JavaScript Let" category: "Frontend" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["let keyword", "block scope", "let vs var", "let hoisting", "ES6 let"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.88 created_at: 2026-06-23 updated_at: 2026-06-23 review_reason: "" merge_history: [] tags: ["javascript", "js", "web", "frontend", "w3schools", "let", "block-scope"] raw_sources: ["https://www.w3schools.com/js/js_let.asp"] applied_in: [] github_commit: "" --- # [[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 scope** β€” `let` variables cannot be redeclared in the same scope (whereas `var` can). [S1] - **Hoisted but not initialized** β€” `let` 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] ```javascript { 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] ```javascript 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] ```javascript { 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] ```javascript let x = "John Doe"; let x = 0; // Error ``` Variables defined with `var` can be redeclared: [S1] ```javascript 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] ```javascript 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] ```javascript 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] ```javascript 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] ```javascript carName = "Saab"; let carName = "Volvo"; // ReferenceError ``` By contrast, variables defined with `var` are hoisted to the top and can be used before declaration: [S1] ```javascript 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: ```javascript { let x = 2; } // x can NOT be used here ``` Safe shadowing: ```javascript 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) - **μƒμœ„/루트:** [[JavaScript Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[JavaScript Variables]], [[JavaScript Const]], [[JavaScript Statements]] - **μ°Έμ‘° λ§₯락:** The block-scoped declaration keyword, contrasted against `var` and paired with `const`. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” JavaScript Let β€” https://www.w3schools.com/js/js_let.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript Let" page (Astra wiki-curation, P-Reinforce v3.1 format).