1.What is the difference between var, let, and const, and what is the temporal dead zone?
Warm-upWhat a strong answer covers
- var is function-scoped and hoisted with an initial value of undefined; let and const are block-scoped ({ } bounded).
- let and const are hoisted too but not initialized, so accessing them before their declaration throws a ReferenceError. That gap is the temporal dead zone.
- const forbids reassignment of the binding, but the value can still be mutated (a const object's properties can change); it is not deep immutability.
- Practical guidance: default to const, use let when reassignment is needed, avoid var in new code.
Where people lose the point
- Claiming let and const are not hoisted at all, rather than hoisted-but-uninitialized.
- Saying const makes an object immutable instead of just preventing rebinding.
- Confusing block scope with function scope, e.g. expecting a var inside an if to be block-local.