🌎
web.dev
Ctrlk
  • 🌏web.dev
  • ⚙️tools
  • 🔰HTML
  • 🔰CSS
  • 🍒JS
    • 💡tips
    • 🧚technique
    • ⭐feature
    • 🔰concept
    • 🔰compilation
    • 🔰grammar
    • 🔰scope
    • 💍value
    • 🔰variable
      • 🈯variable declaration
        • 📜var
        • 🈯const
        • 🈯let
          • ✅let redeclaration not allowed even in sloppy mode❗️
          • ✅let can't shadow parameter even in sloppy mode❗️
        • 🔰initial value
      • ❗variable redeclaration
      • 🔴accessing variables
      • ❗variable shadowing
      • ❗can't delete variable/function❗️
    • 🔰module
    • 🔰iteration
    • 🔰async code
    • 🔰debugging
    • ⛔Error
    • 🏛️Libraries
    • 🛠️tools
    • ✨examples
    • 💼projects
  • 🔰web component
  • 🌐browser
  • 🔰React
  • Server
  • 🔖附錄
    • 👔custom
    • 🧩three.js
    • 🅰️Google Apps Script
    • 📖JSDoc
    • 📦data structure
    • 🔰algorithm
    • 🔰paradigm
    • 🔰TypeScript
    • 💎resource
Powered by GitBook
On this page

Was this helpful?

  1. 🍒JS
  2. 🔰variable
  3. 🈯variable declaration

🈯let

declares a block-scoped local variable.

  • JS ⟩ variable ⟩ let

  • JS ⟩ declaration ⟩ variable ⟩ let

⭐️ ES6 (2015)

(declaration) declares a local variable in block scope.

⛔ ReferenceError: cannot access '...' before initialization.

  • typeof let/const/class in TDZ gets an error❗️

  • ❗global let shadows global object property❗

  • ✅let redeclaration not allowed even in sloppy mode❗️

  • ✅let can't shadow parameter even in sloppy mode❗️

let is

  • a contextual keyword,

  • not reserved word❗

JS is lenient with var, strict with let.

  • var redeclaration applied even in strict mode❗️, even in strict mode❗

  • let redeclaration not allowed even in sloppy mode❗️, even in sloppy mode❗

雖說似乎有一個奇怪的 "for-init" scope,但裡面 let 變數的表現其實更像是 block-scoped。👉 scopes matter with closures ⟩ ❓

  • ⚖️const / var

  • ⛔temporal dead zone❗

  • ❗var can shadow parameter even in strict mode❗️

  • ❗var redeclaration applied even in strict mode❗️

Previousno const for classic "for"Nextlet redeclaration not allowed even in sloppy mode❗️

Last updated 3 years ago

Was this helpful?