MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/learnjavascript/comments/jic377/javascript_string/gabky5f/?context=3
r/learnjavascript • u/tutorialstonight • Oct 26 '20
javascript string π₯
https://www.tutorialstonight.com/js/js-string.php
31 comments sorted by
View all comments
47
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
21
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
-3
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
1
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
2
I should have mentioned that outside of a function and if itβs within global scope. Not that var is inherently global. My bad
47
u/MrMimmet Oct 26 '20
You should really avoid using 'var' to declare your variables.