Skip to content
UniCircle
EasyConceptualVariables

var vs let vs const

Question JS-VAR-001

Compare var, let and const. Cover scope, hoisting, redeclaration and reassignment, and say which you would use by default.

Show hints
  • Think about what happens inside a for loop with setTimeout.
Show the explanation

Model answer.

  • Scope: var is function-scoped; let and const are block-scoped (they live inside the nearest { }).
  • Hoisting: all three are hoisted, but a var starts as undefined, while let/const sit in the temporal dead zone: touching them before the declaration line throws a ReferenceError.
  • Redeclaration: var x twice in one scope is allowed; let/const twice is a SyntaxError.
  • Reassignment: const cannot be reassigned, but the object it points to can still change.
JavaScript
const user = { name: 'Asha' };
user.name = 'Ravi';   // fine: the object changed, the binding did not
// user = {};         // TypeError: Assignment to constant variable

A classic bug: for (var i = 0; i < 3; i++) setTimeout(() => console.log(i)) prints 3 3 3, because there is one shared i. With let each iteration gets its own i and it prints 0 1 2.

Default: use const, switch to let only when the value must change, and avoid var.

Original UniCircle question. Last reviewed 22 Oct 2026.