Click here to navigate the course.

Drag the edges to resize the window.

In Projects, you can keep track of your progress as you go throught the tasks. Check each item as you complete it!

Code Editor
Learn
Variables

Create a Variable: let

In the final task of the previous exercise you received the following error:

TypeError: Assignment to constant variable.

JavaScript threw an error because you assigned a new value to a constant variable. Constant variables, as their name implies, are constant — you cannot assign them a different value.

Let variables however, can be reassigned.

let meal = 'Enchiladas'; console.log(meal); meal = 'Tacos'; console.log(meal); // output: Enchiladas // output: Tacos

In the example above, the let keyword is used to create the meal variable with the string 'Enchiladas' saved to it. On line three, the meal variable is changed to store the string 'Tacos'.

You may be wondering, when to use const vs let. In general, only use const if the value saved to a variable does not change in your program.

Report a Bug
If you see a bug or any other issue with this page, please report it here.