Declaring global variable using let and const

I have started to seriously learn HTML, CSS and JavaScript about two weeks ago. I’ve only tried a small basic webpage challenge before starting an interactive JavaScript course at Codecademy (thinking I can take that simple webpage to an interactive level after this course… maybe :p. It’s all about the attitude towards my goal right?)

Okay, so I can’t figure whats the differents between assigning a global variable using “let” or “const”. It’s confusing me because in the help (hints) in the exercises its somethings let and other times const and I can’t place a pattern. So what the difference and when to use either?

https://www.codecademy.com/courses/build-interactive-websites/projects/chore-door

const is a constant variable, this variable can’t be re-assigned:

const example = 'hello world';
example = 'hello to you too'; // this will give an error

let variable can be re-assigned:

let example = 'hello world';
example = 'hello to you too'; 
3 Likes

How is “const” used in a function in term of your answer? Is myCalcuations won’t be able reassigned later? Can we replace “const” with “let” in the function below?

const myCalculations = (width, length) =>{…};

can we? Yes. Should we? No

well, works the same:

const myCalculations = (width, length) =>{…};

myCalculations = (surface) => {...} // gives error

Ok, I see. Is the const for myCalculations or for width and length? Thank you.

what do you think? :slight_smile: should be a simple way to test this, right?