Interview Question

What is hoisting?

Declarations are created before execution, but their initialization rules differ.

💡 Concept ✅ Quick Revision ⚡ JavaScript

Answer

Hoisting is an informal term for how declarations are instantiated before statement execution. • Function declarations are initialized with their function objects when the scope is created. • `var` bindings are initialized to undefined before execution reaches the declaration. • `let`, `const`, and class bindings exist but remain uninitialized until their declaration is evaluated.

Example

Code
console.log(value);
var value = 3;
Output
undefined

Quick Revision

Declarations are created before execution, but their initialization rules differ.