the new curriculum 7.0 will use all the new syntax features (ES6 and forward) as part of normal syntax, not as special cases. It will not be soon, but soon-ish maybe
That is pretty straightforward though. Don’t use
var in new code. Just because a legacy feature is being retained for compatibility doesn’t mean you should write new code with that legacy feature.
It’s just not a good idea to tell learners to ignore best practices.
The guidelines are easy.
constif you don’t reassign the variable’s contents after creating the variable (i.e., you only write
myVar = ...once). Use
constas much as you can.
letif you reassign the variable (ok to use as a default if you’re not sure).
varin new code. Think about it very carefully about scope if you are maintaining old code with
there may be some situations in which using
var is inevitable
now it’s on par with current practices, so even there
const should be used
Yeah, I imagine there are a few holdouts that don’t support ES6 fully. Though, that was 6? years ago, so there are fewer and fewer of them.
To me this is similar to my rule of ‘Don’t write new Fortran’. There are some cases where you need to do so, but I still state the rule as an absolute because its shorter, I’m lazy, and I’m secretly a Sith
I’m going to disagree with this. If I remember correctly, way back in the early '90s when I was getting my CS degree, scope was one of the first things we learned about because it is such a fundamental concept of most programming languages. Granted, JS didn’t even exist then and of course Eich chose to pussyfoot around this by ignoring block scope completely. My point is that it is not an advanced concept, it is something that should be taught from the start because it will play a role in everything you do.
As others have said, I don’t think it is that hard to learn these three rules:
- Use const whenever possible
- If the value of your variable will change then use let
- Don’t even consider using var except in very specific circumstances and you understand exactly why you need to use it