🟢 EasyCore JS📖 Theory Question

What is hoisting in JavaScript?

💡

Hint

Declarations are moved to top of scope before execution

Full Answer

Hoisting moves declarations to the top of their scope during compilation — before execution. Initializations are NOT hoisted.

console.log(a); // undefined (not ReferenceError)
var a = 5;

greet(); // Works! Function declarations fully hoisted
function greet() { console.log('hello'); }

sayHi(); // TypeError
var sayHi = () => console.log('hi');

let/const are hoisted but live in a Temporal Dead Zone — accessing them before declaration throws a ReferenceError.

More Core JS Questions

🟢 EasyWhat is the difference between var, let, and const?🟢 EasyExplain closures with a practical example.🟢 EasyExplain the event loop, call stack, and microtask queue.🟢 EasyWhat is the difference between == and ===?

Practice this in a timed sprint →

5 free questions, no signup required

⚡ Start Sprint