Hoisting Explained
Why function and variable declarations appear to be 'moved' to the top of their scope before code runs.
Hoisting is one of the most commonly misunderstood JavaScript behaviors, and it is a near-guaranteed interview question because it explains a lot of seemingly weird code. The core idea is that the JavaScript engine processes declarations in a scope during a compile-like phase before executing any code line by line, which is why you can call a function before its definition appears in the source.
It's like a conference program printed in advance: every speaker's name is listed at the top (hoisted), but if you show up to a talk before the actual speaker arrives, the room is empty (temporal dead zone) rather than having no name on the schedule at all.