DEV Community

Discussion on: ⭐️ Interactive JavaScript Quiz #2

Collapse
 
lydiahallie profile image
Lydia Hallie

Even let and const are hoisted (meaning, the engine does store them in memory, as seen in this gif), they just don’t get initialized with the default value of undefined 😃

Collapse
 
bobby_valenzuela profile image
Bobby Valenzuela • Edited

Is this why a Reference Error is thrown? Because the JS engine knows not to use the global 'randomValue' variable? I.e., JS knows that the variable 'randomValue' is within the current block scope and thus the value of this locally-scoped 'randomValue' should be the preferred variable. So, although JS is aware of this local variable (because of hoisting) nonetheless the reference error is thrown because the variable cannot be referenced prior to being initialized (since we're using const here). Am I right about this?

btw.. ABSOLUTELY loving EVERYTHING you've done. From articles, your personal site, just amazing content all around. Thanks so much for all this amazing material!

I signed up to dev.to just to like your articles haha.

Keep up the great work!

avocados