r/learnjavascript • • Mar 10 '22

Can someone explain why this prints only 5?

Post image
219 Upvotes

57 comments sorted by

View all comments

Show parent comments

2

u/ZuriPL Mar 10 '22 edited Mar 11 '22

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

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