Understanding JavaScript Variable Environment and Hoisting

Day 9: The Variable Environment (Hoisting and TDZ) Today was really about understanding the variable environment, like what actually happens before JavaScript runs my code I got to understand JavaScript doesn’t just execute line by line immediately. Before any code runs, JavaScript scans the scope for variable declarations and sets aside space for them in the variable environment object. Nothing physically moves, it's just JavaScript doing preparation work ahead of execution. That's why some variables appear usable before the line they're written on. This setup phase is what we call hoisting. What is Hoisting? Hoisting makes some types of variables accessible and usable in the code before they are actually declared, as if the variable were defined at the top of their scope. The diagram below illustrates how each type of variable works; #JavaScriptJourney #LearningToCode

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories