Hint
A local var declaration shadows the outer variable from the start of the function — not from where it appears.
var x = 'global';
function test() {
console.log(x);
var x = 'local';
console.log(x);
}
test();undefined local
Explanation: var x inside test() is hoisted to the top of the function. First log sees the hoisted-but-uninitialized x (undefined), not the outer global.
Key Insight: A local var declaration shadows the outer variable from the start of the function — not from where it appears.