November 2022
Beginner
624 pages
13h 39m
English
In this Chapter
Understand the relationship between when a variable is declared, initialized, and used
Impress your friends with knowledge about the temporal dead zone, a source of many a gnarly error!
One of the quirkiest things about JavaScript is this thing known as hoisting. We’ll get to what it means in a bit, but let’s set the stage for it by looking at some examples and figuring out what the right behavior should be. For our first example, take a look at the following code:
function foo() {
return "Yay!";
}
console.log(foo());
What do you think is going to be displayed in our console when this code runs? Here are three choices:
undefined
Error—foo isn’t referenced
Yay!
If you guessed Yay!, you ...
Read now
Unlock full access