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

Hey guys,

I’m nearly done with the basic JS section and done some reading up on ‘Var, const, let’.

I know they declare variables but I’ve just tried reading the differences and I feel it’s more for people who already have some experience with Javascript.

Is it normal to not know what the hell most of it means?

1 Like

Its OK to not know the difference b/w var/let/const as a beginner until unless you are applying daily what you’re learning in Javascript. Eventually everything else will follow up in a few days of regular coding.

1 Like

Very broadly, you can change/reassign the value of a variable declared with let, but not with const.

var is the older syntax, personally I try to avoid using it entirely and just use let and const.

const a = 20;
a = 50; // this won't work

let b = 20;
b = 50 // b is now 50
4 Likes

Rule of thumb

  • Use const if you can

  • Use let if you must

  • Don’t use var

4 Likes

Thanks a lot, that’s made me feel better!

1 Like

You guys are great, thanks for the explanation.

1 Like

Thank you, I’ll follow this until I have more knowledge… Up until then I was using var for everything.

var will work… its just an older part of the language. You see in a lot of introductory materiel and older materiel, but as the language matured, they created let and const to make variables easier so that’s why I recommend everyone sticks to those two.

Why hasn’t FCC updated this yet? It was only when I done some codecademy that I saw the other one’s used.

freeCodeCamp uses let and const in the ES6 section and we are replacing the use of var with let and const as we edit challenges. fCC has a lot of curriculum files though and we are older than let and const are in JavaScript, so it’s a lot of work. We are always looking for more volunteers if you want to help.

1 Like

I see. Makes sense, it’s not effected my learning and will be a while yet before I’m onto that section (going to go back through basics).

At some point I’d love to help out. :slight_smile:

Or you can just use var until you understand what is the difference between them.
It is easier for beginner, because you do not need to worry about scope so much. And it is perfectly valid way of writing JavaScript.

1 Like

Sure, you can use var. Or you could just use let until you understand the difference between let and const so that you never develop the bad habit of using var.

2 Likes

Creating functions is one of the most common, basic things you do in JS and if you are creating functions then you are dealing with scope, so I don’t think it is accurate to say that beginners don’t need to worry about it.

Yes, it is valid JS, no, it is not a best practice and hasn’t been for quite some time now.

I’m not criticizing FCC here, I know this site has been around longer than the ES6 updates were implemented in all the browsers and so all of the beginning stuff still uses var. But in a perfect world it probably shouldn’t any more (and from the above comments it sounds like they are in the process of removing var).

2 Likes

Thanks guy, I’m using codeacademy to help with my FCC and they use let for most things so it’s already becoming a bit more ingrained!

1 Like

I think its still key however to have users understand the use of var early on as its still going to be used in code for some time in yet even if taught not to use it

1 Like

Sure, it’s important to understand how var works in legacy code, but its a bad idea to put var in new code.

2 Likes

Yes I think it’s totally fine , you won’t realise the need of var or let till you start working on production or else if you build a full fledged project by yourself , also it is good to clear this thing up in the beginning of your journey since that will be good but you will need to have a look at these differences time to time depending upon the use case.

1 Like

Hello, welcome and thank you.

Of course it is normal. You can’t expect to understand something from the get go. And you may feel that it isn’t important right now to know the differences and you’re probably right. You understand what a variable is and that goes a long way. To be honest, you can use var for a long time until you get to the sections where it is important to use let, const.

Originally only var existed in JavaScript. Let and const were added later on to add some extra features that exist in other languages and also to make some things easier. For example in nested loops there were some work arounds that are much harder to understand than if you just use let.

Understanding when to use let over var, and why and when to use const is pretty advanced. Let it be for now.

1 Like