What they're testing
A warm-up. The interviewer is checking whether you use the vocabulary precisely or approximately.
The short answer~30 seconds
var is function-scoped and hoisted initialised to undefined. let and const are block-scoped and sit in the temporal dead zone until their declaration — touching them earlier is a ReferenceError, not undefined. const prevents REASSIGNMENT, it doesn't freeze the value: const a = []; a.push(1) is perfectly legal.
The long answer
The difference with real consequences is block scope in loops. With var the whole loop shares ONE binding, so every closure created inside sees the final value — the classic "all three buttons log 3" bug. With let each iteration gets its own binding, so each closure keeps the value from its own pass.
The temporal dead zone isn't trivia: it converts a class of silent failures into loud ones. With var, using a variable early yields undefined and the program limps on to fail elsewhere; with let it stops at the offending line. That's why the modern convention is const by default, let when you reassign, and var not at all.
for (var i = 0; i < 3; i++) setTimeout(() => console.log(i));
// 3 3 3 — một binding duy nhất, đọc sau khi vòng lặp xong
for (let i = 0; i < 3; i++) setTimeout(() => console.log(i));
// 0 1 2 — mỗi lượt một binding riêng
const config = { debug: false };
config.debug = true; // OK: sửa thuộc tính, không gán lại biến
config = {}; // TypeError: Assignment to constant variableWhat they'll ask next
?How do you get real immutability?
Object.freeze() for one level, and it's shallow — nested objects stay mutable. Deep freezing means recursing, or using a purpose-built immutable structure. In TypeScript, readonly and as const exist only at compile time and stop nothing at runtime.
These lose points
- Saying "
constis a constant so it can't change". Half right, half wrong, and a genuine source of confusion.