2.2 Constants

Hello everyone and welcome to the Javascript course where I was talking about constants. First of all we will declare A variable that we're going to call interest rate, we're going to do a "let". we assign it a value. So after initiating it is this value to this variable. We can always change it later We'll define a new value. to this same variable We give it a new value of 1. We make a console.log and we will see what it gives. A value of 1. because quite simply the program runs from top to bottom. However in a real application there are situations where we don't want the value of a variable to change because it will create all sorts of bugs in our application. In this situation instead of using a variable, we use a constant. So, the value of a variable as its name indicates can change but the value of a constant can't change. Here we will replace "let" by "const". The variable of interest on a constant will not change. We have an error at line 2 Uncaught TypeError: Assignment to constant variables so we have an assignment of the type error not captured by a constant variable. We have an error on the value of the variable because we simply can't reassign a constant. If you have to reassign a variable. Then you use "let". That's it for constants we meet again for at the next video where I will talk about primitive types.