🔴 HardHoisting💻 Output Question

Class declaration hoisting (TDZ)

💡

Hint

Classes behave like let/const: hoisted to TDZ, not callable before their declaration. Unlike function declarations which are fully hoisted.

What does this output?

try {
  const obj = new MyClass();
} catch(e) {
  console.log(e.constructor.name);
}

class MyClass {
  constructor() { this.x = 1; }
}

const obj2 = new MyClass();
console.log(obj2.x);

Correct Output

ReferenceError
1

Why this output?

Explanation: class declarations are hoisted but stay in the TDZ — accessing them before declaration throws ReferenceError. After the declaration, they work fine.

Key Insight: Classes behave like let/const: hoisted to TDZ, not callable before their declaration. Unlike function declarations which are fully hoisted.

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