Hello, in this video I am going to discuss constants. So constants also like variables, but as you can sort of tell by the name, they are constant, they the value does not change and the way you create them, you know, the way you initialize them and declare them is slightly different. So we have a regular variable. If I created var one for example, according normal to this, this is just a normal variable. assigning the value nine is how you would do it if it's a variable because you have the gold star and to refer to it anywhere, so I want to print it out, you just do dollar than the name. So this will print out nine, which is pretty cool.
To create a constant, you use the keyword defined so this is a function and you put open and closed brackets semicolon and inside of here, you need two things. First of all, you need the name of the constant so I'm going to call it epic. And you do not need dollar that is not required. Last one difference. Next you specify the value. So it could be five, it could be a Boolean be string could be whatever, whatever, you know, datatype you wanna put there, that's valid.
And to actually use it, you can't just put you know, something like, epic, for example, you have to put constant which is a function, then you specify which constant you want to get the value for. So in my case, epic, and it is case sensitive. So bear that in mind. So if I reload that, we get five printed out. So why go to all this, you know, go, Why go, you know, through all this effort to create essentially, why is a variable when we can do it, you know, quicker using just dollar. The reason it locks, it can't be changed.
So if, for example, I duplicate this line, and I try and put something else like nine, okay, the data type the same doesn't matter, because it will give us an error saying constant epic, already defined and when we actually printed it it printed at five, not the value nine, which will assign it late today. So this prevents reassignment, which is fantastic and that is the main reason why you would use constants. So that's it. If you have any questions, feel free to pop me a message coming up this night and I look forward to seeing you in the next video.