Last updated on July 13th, 2020 at 02:25 pm.
This video is taken from the full course that will teach you HTML, CSS, Programming concepts and Javascript .
Video Transcript:
Hi, and welcome back.
In this video, let’s look at constants, that is ‘const’, the ‘const’ keyword.
Now the ‘const’ keyword can be used to create a read only named constant.
So this is from MDN, from the Mozilla Developer Network.
And it says, the ‘const’ declaration creates a read only reference to a value.
This doesn’t mean the value it holds is immutable.
It just means that the variable identifier cannot be reassigned.
I will read that again.
It says that ‘const’ declaration creates a read only reference to a value.
It doesn’t mean the value it holds is immutable.
It just means the variable identifier cannot be reassigned.
So what does this mean? This means that the identifier of the ‘const’ cannot be redeclared and it cannot be reassigned.
Let me open Scratchpad and we are going to see exactly what this means.
Shift+F4 on Windows should bring up Scratchpad.
There we go.
So, if I declare ‘const VAT’ (Value Added Tax) equals ‘16’.
So this is the identifier.
So this means that we cannot redeclare another ‘const’.
We cannot redeclare another constant with the same name and change it.
We cannot in the same scope.
One of the most important things to understand about this ‘const’ is that most of these rules are based on blocks.
So just hold on.
In a few videos or just in a while, I will look at examples that show something about the blocks.
To show that most of the rules mostly apply in the block level.
So just like ‘let’, you remember the ‘let’ keyword for variable declarations.
It is a block level variable, meaning that it is mostly affected within the block.
Okay.
Now some things about the ‘const’ is that, the identifier syntax or rather the naming convention for the identifier, this is the identifier, it follows the same rules, the same syntax and the same regulations for variables.
And if you go back, you will see the rules that I told you about when naming identifiers for variables.
It cannot begin with a number.
So it can only begin with a letter, an underscore or the dollar sign.
You can go back to the videos where we talked about variables.
You will see all the rules for naming a variable.
And then another thing.
When you declare a constant, it must have an initialization.
So you know with a variable, you can just say ‘var VAT;’ and you will initialize it later.
But in this case, you have to give it an initial value.
Delete that, and delete this one as well.
So that’s it for this video.
We’ve just had a brief, a brief introduction of constants, the ‘const’ in JavaScript.
And we have talked about the naming convention for the identifier, some of the few rules for the const and that this value is not necessarily immutable.
And it’s also important to note that ‘const’ is a block level variable.
And that means it’s mostly affected and affects the block within which it is.
And we’re going to see that in the next step.
So I’m seeing you in the next video.
See you then.
This section is from Learn Javascript from Scratch.
Discover more from Bizanosa
Subscribe to get the latest posts sent to your email.