Problems with creation of variables

Tell us what’s happening:
I have problems between the definitions of let , const and var

Your code so far



Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36.

Challenge: Comment Your JavaScript Code

Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/comment-your-javascript-code

What problems are you having?

Dear @ArielLeslie,
Thank you for the fast reply, i want to know the difference in the usage of const , let and var,
i mean in which specific cases i should use it.
Thank you so much again for the fast reply,
Kind regards,
Ivonne

There are articles on the web that will explain this better than I can, but here goes.

var, is the older way of declaring variables. Everything was declared using var. If you go read about this online they will talk about when var is a good idea to use still. I believe it has to do with global variables, or static variables. I confuse the two because different meanings in some languages but used interchangeably at times. That really doesn’t matter for a decent understanding right now.

const and let were introduced in es6 I believe. The ecma 6 standard of JavaScript that updated the language with arrow functions, etc.

const doesn’t allow a value to be changed after being assigned.

so if I do something like,

const SSN = “123-45-678”

I cannot change SSN without getting an error.

let is used for variables that might change.

They say the good rule of thumb is to use const for everything and then if a value needs to be changed or you foresee it as changing, set it as let.

Hope this helps. Don’t let it mess with your mind too much. Learn it well enough to complete the tasks and it will make more sense in time.

1 Like

Exactly but that array is still the same array, you’re just altering its content :smiley:

The array in memory is still the same