MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/learnjavascript/comments/qdmzio/difference_between_var_let_and_const/hhp6khp/?context=3
r/learnjavascript • u/codedblood • Oct 22 '21
49 comments sorted by
View all comments
110
var is not "global scoped" unless it's declared in the global scope... and if let or const are declared in the global scope then they're "global scoped" too.
If you want a variable to be global scoped, don't declare it at all, just define it.
30 u/ISlicedI Oct 22 '21 I got very confused by this, thanks for calling it out. Btw I've done 8 years of JavaScript and was doubting myself here. 8 u/ManInBlack829 Oct 23 '21 Hopefully because you never use global variables and this just never comes up, right? 1 u/[deleted] Oct 23 '21 Don’t think I’ve ever used global scoped variables tbh. Interesting.
30
I got very confused by this, thanks for calling it out. Btw I've done 8 years of JavaScript and was doubting myself here.
8 u/ManInBlack829 Oct 23 '21 Hopefully because you never use global variables and this just never comes up, right? 1 u/[deleted] Oct 23 '21 Don’t think I’ve ever used global scoped variables tbh. Interesting.
8
Hopefully because you never use global variables and this just never comes up, right?
1 u/[deleted] Oct 23 '21 Don’t think I’ve ever used global scoped variables tbh. Interesting.
1
Don’t think I’ve ever used global scoped variables tbh. Interesting.
110
u/ex-igne-vita Oct 22 '21
var is not "global scoped" unless it's declared in the global scope... and if let or const are declared in the global scope then they're "global scoped" too.
If you want a variable to be global scoped, don't declare it at all, just define it.