Is it normal for a beginner to not understand 'Let, Const, Var' differences?

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

2 Likes

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.

  • Use const if you don’t reassign the variable’s contents after creating the variable (i.e., you only write myVar = ... once). Use const as much as you can.

  • Use let if you reassign the variable (ok to use as a default if you’re not sure).

  • Don’t use var in new code. Think about it very carefully about scope if you are maintaining old code with var.

1 Like

there may be some situations in which using var is inevitable

like, Google Scripts (it’s a tool that let you create javascript scripts and execute them on a timer) until a few months ago would only allow ES5 and so only var

now it’s on par with current practices, so even there let and 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 :smiley:

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:

  1. Use const whenever possible
  2. If the value of your variable will change then use let
  3. Don’t even consider using var except in very specific circumstances and you understand exactly why you need to use it
1 Like