🟑 MediumHoistingπŸ’» Output Question

Hoisting with default exports and imports

πŸ’‘

Hint

Hoisting rules are the same in ES modules. Function declarations hoist completely; const/let are in TDZ. Import statements are hoisted (evaluated first), unlike require().

What does this output?

// In JS modules, what does this log?
// Assume these run as module code

console.log(add(2, 3));

function add(a, b) { return a + b; }

console.log(multiply(2, 3));

const multiply = (a, b) => a * b;

Correct Output

5
ReferenceError: Cannot access 'multiply' before initialization

Why this output?

Explanation: Function declarations are fully hoisted β€” add() works. const multiply is in TDZ until its declaration β€” accessing it throws ReferenceError. Same rules apply in modules.

Key Insight: Hoisting rules are the same in ES modules. Function declarations hoist completely; const/let are in TDZ. Import statements are hoisted (evaluated first), unlike require().

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