🌎
web.dev
Ctrlk
  • 🌏web.dev
  • ⚙️tools
  • 🔰HTML
  • 🔰CSS
  • 🍒JS
    • 💡tips
    • 🧚technique
    • ⭐feature
    • 🔰concept
    • 🔰compilation
    • 🔰grammar
    • 🔰scope
    • 💍value
    • 🔰variable
      • 🈯variable declaration
        • 📜var
          • ✅stop using var❗️
          • ❗var is a statement❗️
          • ❗var has no block scope❗️
          • ❗accessing var before declaration gets undefined❗️
          • ❗global var / function is global object property❗️
          • ❗var redeclaration applied even in strict mode❗️
          • ❗var in block can't shadow outer let❗️
          • ❗var can shadow parameter even in strict mode❗️
        • 🈯const
        • 🈯let
        • 🔰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
  4. 📜var

✅stop using var❗️

"var" has a lot of problems, don't use it.

JS ⟩ variable ⟩ var ⟩ stop using var❗

  • var is a statement❗️(side effects)

  • global var / function is global object property❗️(side effect)

  • accessing var before declaration gets undefined❗️(unexpected result)

  • var has no block scope❗️ (unexpected result)

  • var in block can't shadow outer let❗️(unexpected result)

  • var can shadow parameter even in strict mode❗️(bad practice)

  • var redeclaration applied even in strict mode❗️(bad practice)

  • statement expected❗️❗

  • ✅ always use strict mode

PreviousvarNextvar is a statement❗️

Last updated 3 years ago

Was this helpful?