Published: 13 Jan 2026
EPISODE 3 – Hoisting
Ever wondered why JavaScript code sometimes runs even before you write it? The answer is hoisting.
In this episode, we explain how hoisting works and how it affects variables and functions:
- Hoisting is JavaScript’s behavior of moving declarations to the top of their scope during the compilation phase. This is why you can call a function before it appears in the code.
- var variables are hoisted with an initial value of undefined, which can lead to unexpected bugs if accessed before assignment.
- let and const are also hoisted but reside in a Temporal Dead Zone (TDZ) until declared. Accessing them before declaration results in a ReferenceError.
Understanding hoisting helps prevent weird crashes and undefined behavior in your code. Always declare variables and functions before using them to maintain clean, predictable JavaScript.