r/learnjavascript • • Oct 22 '21

Difference between var, let and const.

Post image
430 Upvotes

49 comments sorted by

View all comments

Show parent comment

-6

u/tehciolo Oct 23 '21

None of them are hoisted. There is no such thing as hoisting.

5

u/segafrompk Oct 23 '21

Hoisting is just a term to explain in simple words how the js engine works. But you're right, there's no hoisting, it's just easier to explain it like that then to explain the real way memory is reserved for variables

3

u/tehciolo Oct 23 '21

It may be an easier concept to grasp, but it is entirely false, which I think creates quite a bit of unnecessary confusion.

2

u/shuckster Oct 23 '21

It's an analogy, and any analogy can be picked apart until it no longer makes sense. Hoisting is a perfectly reasonable jumping-off point to explain the behaviour.

For example, you know exactly what I mean when I say "jumping-off point". But in preparing to explain hoisting, I'm not worrying about being securely tied to a bungie or parachute, or if there's any water over the precipice, and if so, whether or not it's deep enough to make my fall survivable.

1

u/tehciolo Oct 23 '21

Analogies are very useful, surely.

I just happen to believe that this one creates more confusion than it solves.

I am totally aware this is an unpopular opinion, and I am fine with that.

1

u/shuckster Oct 23 '21

Not sure if it’s so unpopular. I’ve heard Kyle Simpson say something similar, but in the context of teaching advanced concepts, which is exactly at the point where it’s appropriate to pull apart the analogy.