Let’s first talk about what Let and Const actually mean. Let stands for “letting” and Const stands for “Constant“. That alone should already give you a hint if it doesn’t let me break it down for you with an example.
// Dear computer, can you please let // this day = "Wonderful"
Which obviously translates to:
let night = "Wonderful"
Pretty logical, or isn’t it?
Const, on the other hand, explains itself pretty well. You use Const, or Constant for that matter, for variables that do not change. Let me give you another example.
let isSnowing = true isSnowing = false console.log(isSnowing)
Can you guess what the output of this is? If you guessed false, you are right.
We first assign isSnowing the boolean value of true, and then re-assign it the value false a line below. The ultimate result is false.
Now, what happens if we refactor this code to use Const instead of Let?
const isSnowing = true isSnowing = false console.log(isSnowing)
We receive an error message:
If we go ahead and comment out isSnowing = false, our code will run:
const isSnowing = true // isSnowing = false console.log(isSnowing)
Why Const and Let were implemented?
If you have asked yourself this question by now, I got the answer to you: Readability.
To understand the difference between let and const, you have to simply think about the readability of code. If somebody else has to work on your code and sees a Const variable, he immediately knows that this is a fixed value and it is not going to change later on in the code, making it much easier for him or her to understand your code, whereas the opposite is true for Let.
Once I dug a little deeper it made perfect sense to me as well.