DEV Community

Cover image for Demystifying Scope in Javascript ⚡

Demystifying Scope in Javascript ⚡

Parth Panchal on January 16, 2021

In this blog, let's start from the bare basics to all the way getting comfortable with understanding scopes in Javascript ❤️ . So first and foremo...
Collapse
 
lyrod profile image
Lyrod

It seems to me that as soon as var is used, the JavaScript runtime interprets the variable and sets undefined by default until it is assigned

Collapse
 
parthpanchal123 profile image
Parth Panchal

This happens because of a concept called Hoisting in JavaScript. JavaScript checks through all var variables in the script and kind of lifts them to the top of the script making them available , but undefined until they are assigned . Try the same with let and const and it won’t work because let and const variables cant be used before they are defined . This is also called as a temporal dead zone . Hope you got it :)