They differ in three ways: scope, hoisting behavior, and reassignment.
js
() {
() {
a = ;
b = ;
c = ;
}
.(a);
.(b);
}
They differ in three ways: scope, hoisting behavior, and reassignment.
() {
() {
a = ;
b = ;
c = ;
}
.(a);
.(b);
}
var is function-scoped, hoisted and initialized to undefined, and can be redeclared. This causes surprising leaks — avoid it.let is block-scoped ({ }), reassignable, and lives in the temporal dead zone until its declaration line (accessing it early throws).const is block-scoped and cannot be reassigned — but note the binding is constant, not the value:const user = { name: "Ann" };
user.name = "Bob"; // ✅ allowed — mutating the object, not reassigning
user = {}; // ❌ TypeError — can't rebind `user`
Default to const; switch to let only when you must reassign; never use var in new code. This makes intent clear ("this won't change") and avoids the scope leaks and hoisting confusion var brings.