← All tutorials

GoCareerGo Tutorials

JavaScript Tutorial

Variables to closures, promises, the DOM and OOP — a complete JS reference.

var vs let vs const — Differences

A side-by-side comparison of the three variable declaration keywords in JavaScript.

  • Scope — var: function scope · let/const: block scope
  • Hoisting — var: hoisted & initialized to undefined · let/const: hoisted but in the temporal dead zone
  • Redeclare — var: allowed · let/const: SyntaxError if redeclared in same scope
  • Reassign — var/let: allowed · const: not allowed (but object/array contents can still mutate)
  • Global object — var creates a property on window/global · let/const do not
Tip

Give the one-line rule: 'const by default, let if you need to reassign, var almost never.'