Why do we still teach var?

Early on in the javascript tutorial, we hit the Global Scope and Functions page. It says

You should always declare your variables with var .

I’m newer to Javascript, but with ES6 everything seems to say never use var, only use let and const. Why is this website still teaching var? It should be noted that I love this website. I’ve used it for a few things. This one sentence seems to go against everything else I’ve learned about javascript.


The curriculum is huge and maintained by volunteers, and changing from var to let/const involves updating say 90% of all the code, all the tests, all the instructions, all the examples, all the hints/example solutions, all the code that tests the code that does the tests, and that really has to be done all at once rather than piecemeal. There is also the reasoning that var works everywhere, in every browser that’s ever supported JS, and will never be deprecated, but I think the first reason is more important one. And yep, let and const are specifically there to fix the problems with var, and basically obselete it in almost all situations, and should definitely be used as a matter of course. The curriculum does get fixed, it’s just that massive changes like this are so big that they take a very very long time to work their way in.

You gotta bear on mind that this is a very recent thing: let and const were only added to the actual language standard 4 years ago, and lots of the curriculum is around about that old (it’s all still valid though!). They didn’t work reliably cross-browser without compiling code to use var (still don’t if you have to support what are now very old browsers!), It’s only really been in the last couple of years that it’s gotten fairly safe to use them without really worrying about code not working.


Thanks for the reply. Good points all around. :slight_smile: It didn’t realize how much of it was volunteer work.

1 Like