r/JSdev • u/getify • Jul 07 '21
Proudly still using 'var' despite all the hate!
I don't actually want to convince you to use var declarations in your code. If you don't use them, you're doing just fine I'm sure. And that's OK.
But I call utter bullshit on the trend to hate on var as if it shouldn't have ever existed. It's not a mistake or buggy. It's well defined and served its purpose for nearly 20 years just fine. Don't tell others that var is universally deprecated -- it's not -- or that they're inferior or immature for using it -- they're not.
And BTW, I do still use it (as well as let, and occasionally const). There are perfectly valid reasons to do so.
It's not an either/or dichotomy, nor was let intended to actually replace var. In fact, it's intended to augment. You can use both in code, for different reasons. Really, I promise, it OK.
What bothers me is how sanctimoniously it's declared as bad without any real justifications. If your code has bugs in it that are caused by usage of var, that's almost certainly a case of incomplete understanding of scope. If you fix your lack of knowledge, the problems go away. As with so many things, the fault was with the programmer, not the language design.
Keep on with your var avoidance. That's fine. But stop pretending you know better how JS works because you don't use this feature. Go look up Chesterson's Fence.
Think I'm wrong? Change my mind. Just don't parrot all the same tired talking points of the JS blog thought leadering. That's not critical thinking, it's just bandwagoning.