FAQ: Variables - Create a Variable: let

let keyword (const and var as well) can only be used when declaring a variable. Not when re-assigning an existing variable

as for the other part of your question, easy enough to test right?

1 Like

Yeah I’ll just test it out.
Thank you.

Confusion with assigning…

  1. Why is this wrong :
    let meal = ‘Enchiladas’;
    console.log(meal);
    let meal = ‘Burrito’;
    console.log(meal);

And this correct?:
let meal = ‘Enchiladas’;
console.log(meal);
meal = ‘Burrito’;
console.log(meal);

  1. Why does var not follow the same guidelines and what’s the difference with not using either like this, which works :
    meal = ‘Enchiladas’;
    console.log(meal);
    meal = ‘Burrito’;
    console.log(meal);

let and var say something about the scope of a variable, so we only need this keyword when declaring a variable. We can’t change the scope when re-assign the variable.

Thanks for asking. I have the same Q…

why when you are reassigning a variable, you can omit let? Is better to omit it or not?

This is because you are not declaring the variable and instead you are just changing the value.

1 Like