2.4 Let & const

Hello everyone I hope you are doing well we meet today for a new video and in this video we’re going to talk about let and const So let and const. These are two keywords that you will see quite often in this course and in this course, you will see in particular const. Let and const are different ways to create variables. I think you know VAR, var creates variables in javascript Now the thing is that some variables never change these are called constants. Technically, they are. They are only variables, because javascript knows only var.

With ES6, a version of javascript, two different keywords were introduced, these are let and const. Var still works but you are strongly encouraged to use let and const. made Let and so to speak the new var, you use it for variable values. but the most important solution here is to use let if you want to create a variable that is really variable. Use const if you plan to create a constant value, something that you only assign once and change never. And this is the case more often than you think. So in this course you will never see var, you will only see let and const and especially const. So it shouldn’t confuse you, it’s just the same ar, but in a way more modern, and in the case of const, although this is clearly stated, it will never receive a new value. Now, since this is always a little clearer in practice, let’s take a look at it.

For this, it is better to use jsbin.com, it is another Web editor which facilitates javascript entry and visualization of some console outputs disable HTML and outputs up there and, instead, activate Javascript and the console. how to do it? it’s very simple You have HTML and Javascript you just have to click on the small html and it will no longer be there and you leave the javascript Now you have JavaScript enabled and you have the console on the right, we can start so from here we can create a variable so we’re gonna be able to create our little code jam we’ll create var myName N capital letter is very important and equal and we’ll write my Matthew name so I’ll put a little capital M here and of course semicolon don’t forget the semicolon Then below we will write console.log myName always the uppercase M really don’t forget that And if we run it will write Matthew here’s what was put here and of course we can also do myName and equal matthew semicolon and write this console log let’s imagine we’re going to mark Lucie so I erased everything and if we put lucie with matthieu It’s gonna give us Matthew Lucy here we can write about different way now if we exchange here the var for let that we erase and put it running it still works you see it works anyway it puts us matthew and lucie it’s perfect but on the other hand if I exchange and that I want to put const

It’s gonna give me an error message, because we are trying to reassign a constant variable which is kind of a strange name you can say that this should never get a new value and that if you then inadvertently write the code you reassign, you get the error and therefore a chance to improve your code. here you have understood this little course on let and const thank you for watching and we’ll see you on the next video