In the last videos, we haven’t really talked much about the block scoping.

Especially with the ‘let’ variable keyword.

But after we look at this video, you’re going to understand exactly what I mean.

So I want to introduce some kind of a block here and I don’t want to introduce a function.

So I’ll just do ‘if’.

I’ll just do an ‘if’ block.

So, let’s say ‘true’.

‘if(true)’, do the following statement.

So I will take this and put it within this block.

And this is going to help us.

This is going to help us explain a lot of things.

The reason I don’t want to use Scratchpad without any kind of block is because of some issues we experienced with you in the last videos whereby once I declare a variable and I run it, the variable is still stored in the browser memory.

So if I introduce a block, it will help us curb such kind of issues.

So here we have an ‘if’ block.

So basically, we’re going to look at these kinds of statements in future.

Don’t worry much about this.

I’m just using this so that I can explain the ‘const’.

But we are going to look at things like, ‘if’, ‘if-else’ in upcoming videos.

If not in upcoming videos, in upcoming courses.

So just bear with me.

So basically, what this does is ‘if’ true, do whatever is inside this block.

So, the only reason I’m using the ‘if’ is so that I can introduce a block.

So that’s a full block there.

And we know that ‘const’ as I said in the last video, ‘const’ is a block level variable.

And one thing I didn’t say in the last video is, once you declare a variable, once you declare a constant, ‘const’ with an identifier, you cannot use the same identifier to declare another variable.

So for example, let me say I try to say ‘var VAT;’.

If I try to do this, this’ll give me an error.

So if I try and run this, you see it says ‘redeclaration of const VAT’.

And that is the same for ‘let’.

Even if I change the name of this to ‘VAT2’ and ‘VAT2’.

So, and I try to run this, it will still give us the same error, ‘redeclaration of const VAT2’.

So you cannot use the same identifier that you’re using for a constant to declare another variable.

And you can also not use the same identifier to redeclare a function.

So if I say ‘function VAT2’, just that and let me remove this.

And if I try to run, ok.

Let me pull these ones here.

And if I try to run this, it also ‘missing ; before statement’.

Why is that? Okay, okay, okay.

This is ‘function’ not ‘fucntion’ whatever that is.

So, if I run this, you see ‘redeclaration of const VAT’.

So that basically means you cannot use the same identifier for a function, a variable within the same scope, if you’ve already used the same identifier for a constant.

So I hope you’ve understood the identifier thing, where you cannot use the same identifier for the same constant and also for a variable.

Bizanosa / Ricky Wahowa

Ricky provides online tutorials in Web related topics. The internet connects us all. He specializes in some back end and Front End web technologies. And has acquired web Marketing skills along this journey.

We use cookies on Bizanosa.com. Continuing to use this website, implies consent of our Privacy Policy Privacy Policy

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.