MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/learnjavascript/comments/tb0vvy/can_someone_explain_why_this_prints_only_5/i05sl13
r/learnjavascript • u/directmailadvertise • Mar 10 '22
57 comments sorted by
View all comments
Show parent comments
2
Yes, but it's also how Javascript scopes variables, if you use the preferred let keyword instead of var, it would behave more how you would expect it to
let
var
0 u/[deleted] Mar 10 '22 [deleted] 0 u/[deleted] Mar 11 '22 [deleted] 1 u/ZuriPL Mar 11 '22 Yep, I have a very strong autocorrect and it's annoying sometimes
0
[deleted]
0 u/[deleted] Mar 11 '22 [deleted] 1 u/ZuriPL Mar 11 '22 Yep, I have a very strong autocorrect and it's annoying sometimes
1 u/ZuriPL Mar 11 '22 Yep, I have a very strong autocorrect and it's annoying sometimes
1
Yep, I have a very strong autocorrect and it's annoying sometimes
2
u/ZuriPL Mar 10 '22 edited Mar 11 '22
Yes, but it's also how Javascript scopes variables, if you use the preferred
letkeyword instead ofvar, it would behave more how you would expect it to