DEV Community

Cover image for 🔥🕺🏼 JavaScript Visualized: Hoisting

🔥🕺🏼 JavaScript Visualized: Hoisting

Lydia Hallie on November 20, 2019

Hoisting is one of those terms that every JS dev has heard of because you googled your annoying error and ended up on StackOverflow, where this per...
aminnairi profile image

Your GIFs are on point! Very good article. I think most of us know or have heard about hoisting but this makes it totally clear in my head now. Keep up the good work!

lvidakovic profile image
Luka Vidaković

It's a nice refreshment to see gifs that break up the text to digestible chunks while also helping with the visualization. Keep it up!

Hoisting is often explained as putting variables and functions to the top of the file

I can see why it's described that way to some extent. Parser needs to go over the whole file/script, and it only does something meaningful with functions, and vars at first. So at the top of the file, very first line, you already have the access to those identifiers.

lydiahallie profile image
Lydia Hallie Author

It’s just important to understand that the parser is not actually physically moving them to the top - as some people like to explain it

lvidakovic profile image
Luka Vidaković

Yup I agree. Semantically it only makes difference with vars, but you descriptions are to the point 👌

Thread Thread
shafkathullah profile image
Shafkathullah Ihsan

Testing comment UI...

Thread Thread
shafkathullah profile image
Shafkathullah Ihsan • Edited

2Testing comment UI...

jimisweden profile image
Jimi Friis • Edited

It's such a simple thing to explain when looking at yours.. I wonder why so many teach the "Hoisting is often explained as putting variables and functions to the top of the file" - perhaps that's what they learned; perhaps it is the fallacy of thinking "people won't understand because it's complex".
If someone would have asked me to explain hoisting before reading this article I would fall back on that explanation but not really knowing why; now I know better! I have quite good understanding of javascript (for being a mostly C# developer - learning react) and like to know what is going on, one of my favorites in the JS world to read and listen to is Kyle Simpson ('You don't know JS' , + 'Yet') - he is awesome , but you know what.. you, Lydia, are fantastic teacher and a ⭐ on the same sky as Kyle.

I hope you take this advantage to a next level and produce courses on Udemy and/or Pluralsight - I think you could make a fortune (or at least some extra cash) on it 😄

Keep it up 💚 !

matijazx profile image
Matija X

That's reason I love this site. I just learn JS and term hoisting was unknown for me until this moment. I read text above and resolve my doubts. Thx!

lfkwtz profile image
Michael Lefkowitz

Love this entire collection, Lydia. Shared them all in my react native newsletter

namkwon profile image
Nam Kwon

Great article! What about const function? ex. const sum = (x,y) => x+y

beginwithjs profile image

You may consider it as the "hoisting variable const" situation.

islamhanafi94 profile image
Islam Hanafi Mahmoud

First things first, thank you Lydia for this amazing topic. and I've a question regarding using let.

I think let variables is initialized to with undefined. but due to being in temporal zone it's value is inaccessible.

I tried

let x;
console.log(x); // resulting >> undefind

fahim04blue profile image
Shahriar Saleh Fahim

It results undefined because you have initialized the variable 'x' already but haven't defined the variable with any value. This is why it prints out undefined.

inrsaurabh profile image
Saurabh Ranjan

Very informative article with amazing GIFs.

How you created these GIFs. Is there any tool or created those animations first than converted to GIFs.

savokiss profile image

Hi, Lydia~ Very nice articles~ Can I translate this series articles into Chinese, I'll keep the original links~

saurabhdaware profile image
Saurabh Daware 🌻

Thank you for explaining how it works internally "var brings variables to top" totally makes sense now!

Thank you for sharing! deserves a lot of 🦄🦄🦄

kinglouisxvii profile image
Daniel Jakobian

love all of your articles, keep up the great work!

_rahulpandit profile image
Rahul Pandit

so interesting explanation

deepanshu188 profile image
Zexu Knub

Thank You so much that actually cleared what hoisting really is

edwinwong90 profile image
Edwin Wong

Well Explained! Keep up for the work you have done!!

kkroeger93 profile image
Kevin-Kelly Kröger

Lydia you cleared everything what was gibberish before. Really enjoying reading your articles. Keep it up :).

tiagoha profile image
Tiago A

JS Developers that use only arrow functions do not understand hoisting.

mathvbarone profile image
Matheus Barone

Awesome content, and really clean explanation.

Thanks for that, and keep up the good work!

gopinathaa profile image

Thanks, Lydia for a simplified & awesome GIF representation.

khpatel4991 profile image
Kashyap Patel

How did you make these visualizations?

cyberburi profile image

Thanks for visualization, perfect! :)

priyank88544513 profile image
Priyanka Singh

Very helpful and to the point!

kingisaac95 profile image
Kingdom Orjiewuru

Hi Lydia, please what tool did you use for the visualizations?

qinlu20 profile image

Wow, that's a great article.I want to translate your article into Chinese so that more people can see it.Do you agree with me to do this?

saleemmalikraja profile image
Saleem Malik

Would you like to share how you prepared this gif?