EasyHoisting💻 Output Question

var declaration hoisted as undefined

💡

Hint

var hoisting: declaration moves to the top, assignment stays. Value is undefined before assignment.

What does this output?

console.log(x);
var x = 5;
console.log(x);

Correct Output

undefined
5

Why this output?

Explanation: var declarations are hoisted (moved up) but not their assignments. First log sees the hoisted-but-uninitialized x.

Key Insight: var hoisting: declaration moves to the top, assignment stays. Value is undefined before assignment.

More Hoisting Output Questions

EasyFunction declaration fully hoistedEasyFunction expression not hoistedMediumLocal var shadows outer — from start of functionMediumFunction declaration takes priority over var in hoisting

Practice predicting output live →

66 output questions with instant feedback

💻 Try Output Quiz