r/learnjavascript • • Oct 26 '20

Javascript string πŸ”₯

193 Upvotes

31 comments sorted by

View all comments

47

u/MrMimmet Oct 26 '20

You should really avoid using 'var' to declare your variables.

21

u/I-DONT-WANT-GOLD Oct 26 '20

Why?

-3

u/EIGRP_OH Oct 26 '20 edited Oct 27 '20

i.e lives ans dies in the scope it is declared, whereas var is global and can be used anywhere.

Var also puts variables on the global Window object where Let and Const don't.

EDIT: for those downvoting this can you explain why I’m wrong instead of downvoting? I’d genuinely like to know.

1

u/awkreddit Oct 27 '20

Var is not global

2

u/EIGRP_OH Oct 27 '20

I should have mentioned that outside of a function and if it’s within global scope. Not that var is inherently global. My bad