Explain Hoisting in JavaScript.

  • Hoisting means variable and function declarations are moved to the top of their scope before code execution.

Example:

console.log(a); // undefined
var a = 5;
  • var is hoisted (declared but not initialized).
  • With let and const, hoisting happens too, but they remain in a temporal dead zone until declared.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *