DEV Community

Discussion on: JS interview in 2 minutes / var ⚔️ let ⚔️ const

Collapse
 
lowla profile image
Laureline Paris • Edited

Hi there 🙌
I do not agree with how you define hoisting even though it’s not entirely false.
I would have say « you encounter hoisting problematic when you call a variable before it’s assignations »
But hoisting perse is how javascript handle your code and how it would read it - which leads to : it’s insightful to understand how javascript works .
When reading one’s code Javascript has hidden process which includes hoisting.
Hoisting is the fact that javascript reads your file and before executing your lines it hoists your variable and function ( meaning that it keeps the the variables declaration, without their value, and functions on « top of the file » before processing to any logic

Common cases are when one calls either a function ( with function keyword ) or variable with the « var » ’ keyword - indeed - before their definitions. :)

Then this was exactly why let and const were created in order to have a better control of those - ( good to know ) knowing that non mutable objects prevents from memory allocation loss in any programming language

[ edit ] Here is a the doc to which we can understand the arguments I have above regarding the def of hoisting developer.mozilla.org/en-US/docs/G...

Collapse
 
hexnickk profile image
Nick K

Thanks! I actually didn't realise that hoisitng can be useful with function declaration. Let me just add an update pointing to your comment. Thanks again!