Can I reassign variables using 'let'?

You must select a tag to post in this category. Please find the tag relating to the section of the course you are on E.g. loops, learn-compatibility

When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!

If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer! :slight_smile:

Dumb question but can you not reassign a variable using “let”? This is in reference to Intro to JavaScript.
https://www.codecademy.com/courses/introduction-to-javascript/lessons/variables/exercises/typeof

var, let, and const are declarations for when you first declare a variable.

right. yes I got that, and using let to reassign did not work. so to reassign, you just do the variable and then the value?

e…g.
var myCity = “Miami”;
myCity = “New York”;

thank you!

Correct that is how you do it. It is preferred not to use var since ES6 with the addition of let and const.

thanks. one question, since you are here, what are “let” and “const” and “var” called? i mean i know they are representing variables but is there a name for the declarations or are they just called declarations

var: variable
let: Let this be a variable (I made this up)
const: constant

They are keywords used in variable declarations.

1 Like

Can’t do this:

let x = 5;
let x = 3;

(Although that might work if you used var instead of let.)

Can do this:

let x = 5;
x = 3;