What is hoisting in JavaScript?

Answer

Hoisting is JavaScript's behavior of moving declarations to the top of their scope during the compilation phase, before code execution. For var declarations: the variable is hoisted and initialized to undefined — you can access it before the declaration line without an error, but its value is undefined. For function declarations: the entire function (name + body) is hoisted — you can call it before it appears in the code. For let and const: they are hoisted but NOT initialized — accessing them before the declaration throws a ReferenceError (they exist in the "temporal dead zone"). For function expressions and arrow functions (stored in variables): only the variable declaration is hoisted, not the assignment — calling them before the assignment throws a TypeError.