Hint
var escapes blocks. let/const are block-scoped. typeof on a block-scoped variable outside its block returns "undefined".
function test() {
if (true) {
var x = 10;
let y = 20;
}
console.log(x);
console.log(typeof y);
}
test();10 undefined
Explanation: var x escapes the if block (function-scoped). let y is block-scoped — inaccessible outside. typeof y returns "undefined" safely.
Key Insight: var escapes blocks. let/const are block-scoped. typeof on a block-scoped variable outside its block returns "undefined".