πŸ”΄ HardHoistingπŸ’» Output Question

Function vs var hoisting order

πŸ’‘

Hint

Function declarations win over var during hoisting. But later assignments still overwrite.

What does this output?

console.log(foo);

var foo = 'bar';

function foo() {
  return 'function';
}

console.log(foo);

Correct Output

[Function: foo]
bar

Why this output?

Explanation: Function declarations take priority over var during hoisting. So foo is the function initially. Then the var assignment overwrites it with "bar".

Key Insight: Function declarations win over var during hoisting. But later assignments still overwrite.

More Hoisting Output Questions

🟒 Easyvar hoistingβ†’πŸŸ’ EasyFunction declaration hoistingβ†’πŸŸ‘ MediumFunction expression not hoistedβ†’πŸŸ‘ Mediumlet temporal dead zoneβ†’

Practice predicting output live β†’

66 output questions with instant feedback

πŸ’» Try Output Quiz