Back to search

Variables in JavaScript: var, let, const, scope rules, hoisting, and the temporal dead zone

Use `let` and `const` for block scope, remember that `var` is function-scoped, and know that hoisting behaves differently across them.

JavaScript Easy Theory

Variables in JavaScript: var, let, const, scope rules, hoisting, and the temporal dead zone

Use `let` and `const` for block scope, remember that `var` is function-scoped, and know that hoisting behaves differently across them.

  • `var` is function-scoped
  • `let` and `const` are block-scoped
  • TDZ applies before `let` and `const` initialization

Variables in JavaScript: var, let, const, scope rules, hoisting, and the temporal dead zone