No, I think that is too simplistic.
"It shouldn't be used most of the time."
There are a few edge cases where having the variable hoisted is very useful and saves time when needing to get things done quickly. As others have said, time is valuable.
But in general, I agree, I always use linting and have a favourite, slightly adjusted version of "Standard" JavaScript that I prefer to use. Full Standard is rather overly aggressive for my liking.
But then, I'm not part of a team and if I were, I'd need to work to the team standards not my own.
It does take a while to get used to it. But in general, it does save you from some subtle bugs that can be really hard to track down. I don't regret training myself to commit var
to the very bottom of my bag of tricks.
That is certainly a good point. Though one doubtless countered by many open source developers who might say that they don't develop for that reason.
Personally, I like to write the best code I can, and often refactor old code if I come across it in the future with more knowledge to hand. But that is me and one of the reasons I code personally is for the creative joy of it. So I personally consider that time investment well worth while.
But even I will only do this if there is also some other reason to update things. I don't have the capacity to rewrite old code just for the sake of it I'm afraid.
Actually, BBC Basic was a superb and well structured language. But yes, it was certainly easy to trip yourself up. Just be thankful that you never had to deal with APL! I once had to spend an entire week pondering over a calculated goto in APL.
Hmm, I'd say that mostly the use of var
in new code is bad code. It does greatly annoy me when people trying to show others how to do things in articles in 2024 use var
indiscriminately. There is no call for that. What's worse is that this then gets picked up in LLM's and so you end up with perpetuated bad code.
The use of var
in old code is expected. But worthy of updating if making amendments anyway and if time allows. I have found bugs lurking due to incorrect use of var
, so there is certainly value in this.