Javascript Hoisting | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Javascript Hoisting

hello, i wanted to share something with you, how javascript hoisting works, hoisting is just setting variables and functions in memory, probably if you search on internet about it, you'll find that variables and functions are placed at the top of the document, but that isn't what actually happen, so now you know, var and func are in memory when you run js waiting until you call them. ***** hoisting es reservar un espacio en la memoria para las variables y funciones no ponerlas en el principio del documento.

4th Apr 2017, 6:11 PM
Victor_*
Victor_* - avatar
2 Answers
+ 1
if you liked the info, please let me know and i will continue sharing info with you (scope chain, coercion, etc)
4th Apr 2017, 6:48 PM
Victor_*
Victor_* - avatar
0
Actually Hoisiting is Javascript's behaviour of placing declarations at the beginning of the scope. For example in: function random(){ x=10; alert(x); } var x; x is declared at the end of the script but because of hoisting it is placed at the top of the scop(in our case the script). However hoisting doesn't affect initializations For example if I put "var y=10;" at the end of the scope(be it either script or function) the value of y will be undefined if it is used before I declared it like above, this is because hoisting only places on top the declaration ("var y") not the initializer ("=7"). There's a nice article on W3Schools about this, and they're not the ones to spurt dumb articles on the internet. Hope this helped. Oh it appears there's also a sololearn Q&A Discussion about this.
20th Aug 2017, 4:24 PM
TheBlackYellow
TheBlackYellow - avatar