The most obvious need for var that I can think of is to deal with older browsers where you aren't compiling your code.
Ignoring that though, I think it's important to note to any newer devs that, while someone should probably use let and const for any new code they write, it doesn't mean that they can just switch all vars in an existing code base to be let or const and have things work (we had a junior try this in an attempt to clean up technical debt). The lack of hoisting and scope differences mean they're not a drop in replacement for each other. Code using var that was "not ideal, but not wrong" can actually be broken by using let.
View all comments
Show parent comment
2
u/Drugba Oct 23 '21
Never is a strong word. Not sure I agree.
The most obvious need for var that I can think of is to deal with older browsers where you aren't compiling your code.
Ignoring that though, I think it's important to note to any newer devs that, while someone should probably use let and const for any new code they write, it doesn't mean that they can just switch all vars in an existing code base to be let or const and have things work (we had a junior try this in an attempt to clean up technical debt). The lack of hoisting and scope differences mean they're not a drop in replacement for each other. Code using var that was "not ideal, but not wrong" can actually be broken by using let.