When you attempt to assign a value to a const variable like this example shows:
const myName = 'Seth'; myName = 'Hannah';
If you attempt the code above (assigning a value to a const variable) you will receive the following error:
TypeError: Assignment to constant variable.
Let variables, however, can be reassigned: (see code example below.)
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 code line three (above), 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.
My little pony learning game in VB.NET
How to make a go-back button with PHP code?
Hello World Android app built with Android Studio
Why Python is the cooler programming language
Who is this Android App Development course for?