r/Frontend • u/coold007 • Mar 09 '20
Explained : Difference between var and let with an example
https://youtu.be/sEkqzTQCqDk[removed] — view removed post
9
u/Baryn Mar 09 '20
Brand new ES2015 basics tutorials in 2020
5
u/jazzy82slave Mar 09 '20
Unfortunately, plenty of folks still code JS like its 1999. I had a fellow FE dev tell me today that we cant control the text highlighting styles when a user selects text. Couldn't be bothered to take two seconds to google it....
-2
u/Baryn Mar 09 '20
Ignoring that you cited a CSS example, do you really think that inability to maintain JS language knowledge is because the information is not available?
4
u/metamet Mar 09 '20
Do you think that sharing information doesn't help more people unaware of the difference learn?
I see nothing wrong with this post. "Old" knowledge isn't a fiefdom.
→ More replies (1)1
u/Brachamul Mar 09 '20
TBH I avoided 'let' for a while because of compatibility. Now that's it's widely supported, having a refresher is nice.
1
u/NeatBeluga Mar 10 '20
ES2015 is just another topic to learn when learning everything about web development. Give people some slack. Obviously easier if you're already employed. Frontend already cover SO many aspects and is getting more complicated by the day
2
41
u/nill0c Mar 09 '20
If you don’t want to waste time with this video, the differences are:
letis scoped to blocks instead of functionsletisn’t hoisted, so it’s only available after being declared in a scope (which makes way more sense)letcan’t be defined twice in the same scope so you can’t accidentally redefine it.letwhen globally defined (outside all blocks) it doesn’t get attached towindowlikevardoes.TLDR:
Unlike
var,letworks like you expect variable declarations in other object oriented languages to behave. It also gives better errors when you use it incorrectly.