🟑 MediumHoistingπŸ’» Output Question

Function expression not hoisted

πŸ’‘

Hint

Function expressions stored in var are NOT hoisted as functions β€” only the var declaration is.

What does this output?

console.log(typeof foo);
console.log(foo());

var foo = function() {
  return 'hello';
};

Correct Output

undefined
TypeError: foo is not a function

Why this output?

Explanation: var foo is hoisted as undefined. Calling undefined() throws TypeError. The function is not assigned until that line executes.

Key Insight: Function expressions stored in var are NOT hoisted as functions β€” only the var declaration is.

More Hoisting Output Questions

🟒 Easyvar hoistingβ†’πŸŸ’ EasyFunction declaration hoistingβ†’πŸŸ‘ Mediumlet temporal dead zoneβ†’πŸ”΄ HardFunction vs var hoisting orderβ†’

Practice predicting output live β†’

66 output questions with instant feedback

πŸ’» Try Output Quiz