MediumHoisting💻 Output Question

Function declaration takes priority over var in hoisting

💡

Hint

Function declarations beat var declarations in the hoisting phase. But var assignments at runtime overwrite them.

What does this output?

console.log(typeof foo);
var foo = 1;
function foo() { return 2; }
console.log(typeof foo);

Correct Output

function
number

Why this output?

Explanation: Function declarations win over var during hoisting phase. At start, foo is the function. Then var foo=1 executes at runtime — overwriting with a number.

Key Insight: Function declarations beat var declarations in the hoisting phase. But var assignments at runtime overwrite them.

More Hoisting Output Questions

Easyvar declaration hoisted as undefinedEasyFunction declaration fully hoistedEasyFunction expression not hoistedMediumLocal var shadows outer — from start of function

Practice predicting output live →

66 output questions with instant feedback

💻 Try Output Quiz