What are the differences between `var` and `let`? Are they necessary?

When creating a variable, do you need to use let or var at all if the variable ISN’T going to be a constant? The code still seems to record the variable just fine, and allow changes, whether I use var/let or not. ?

Same with spaces between the +, -, / etc. The code seems to work just fine without the extra spaces so do I really need them, or it’s just accepted practice, or the “standard” that people put spaces between those characters for neatness (or whatever)?

2 Likes

do you need to? No. Should you? Yes.

the keyword (var or let) indicates the scope of the variable, without var, let or const the variable has a global scope. Which is far from ideal

for readability, the spaces are recommended

7 Likes

This post has links to a few articles that explain variable declaration pretty well.

3 Likes

Hello,

But what is the difference between var and let then, if both of them can be reassigned to a diff value later???

Hi,

Also:

7 Likes

I understand that we do not use VAR anymore ?

We can still use var if you have a good reason, but generally not. let and const are preferable.

1 Like