Hoisting is JavaScript's behavior of moving declarations to the top of their scope during compilation. Function declarations and var declarations are hoisted; let/const are hoisted but not initialized.
During the creation phase, the engine registers declarations before executing code. function declarations are fully hoisted (callable before their line). var declarations are hoisted and initialized to undefined, so accessing them early returns undefined rather than throwing. let and const are hoisted but remain in the Temporal Dead Zone (TDZ) from the start of the block until the declaration is evaluated — accessing them there throws a ReferenceError. Function expressions and arrow functions assigned to variables follow the rules of the variable (var/let/const), not function hoisting.
A util file defines helper functions as function declarations so they can be called from the top of the file regardless of order. But converting one to const doSomething = () => {} and calling it above its definition suddenly throws — because the const is in the TDZ.
console.log(a); var a = 1; prints undefined, but console.log(b); let b = 1; throws ReferenceError. Explain the difference.