+ 19

JavaScript Hoisting!

Is this code valid? x = "Sololearn"; document.write(x); var x; The answer is yes because of the little known feature of JavaScript called hoisting. All declarations are moved to the top of the current scope. So, the last line is moved to the top and the code becomes valid. Check this out. https://code.sololearn.com/W6ih00m7yR96/?ref=app

11th Jun 2017, 3:50 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
4 ответов
+ 8
Ohh a new thing...Sir how about commenting it in the course ! Question:- Do the local scope variables also go in the top?
11th Jun 2017, 5:30 AM
Nikhil
Nikhil - avatar
+ 6
Interesting stuff. Was this described in the course at all? If not, it should be be!
11th Jun 2017, 4:45 AM
Rrestoring faith
Rrestoring faith - avatar
+ 3
I didn't know that,really interesting!
11th Jun 2017, 3:59 PM
Haris
Haris - avatar
+ 2
Thanks. Learnt this today. This is actually not a question but personal feed didn't exist 2 years ago, so the post is valid I guess.
30th Jul 2019, 11:07 PM
Sonic
Sonic - avatar