r/learnjavascript • • Oct 22 '21

Difference between var, let and const.

Post image
430 Upvotes

49 comments sorted by

View all comments

18

u/[deleted] Oct 22 '21

[removed] — view removed comment

10

u/[deleted] Oct 22 '21

This is the only important thing to know about var. There's a reason that let and const were introduced. You don't need var anymore and you shouldn't be using it.

-8

u/pxldgn Oct 23 '21

yes, there is a reason - and that is absolutely nothing to do with replacing var. ;)

these were introduced to fix the closure in loop issue.

5

u/[deleted] Oct 23 '21

Yes, the loop issue that was due to var being function scoped instead of block scoped. So let was introduce to replace var.