- [Instructor] The last item we need to cover
is block scope variables.
They were introduced with ES6 and uses
the let and const keywords.
If we go back to local variables they are available
within the function they are declared in.
But with block scope variables they are only available
inside of the block they are declared.
For example, if we take a look at this code
and this code, they are only available
within this block of code.
So, if we declare a variable inside of an if statement
in a function, this variable won't be available
in the function outside of the if statement
because it is block scoped, inside of the if statement
and so on, so forth if you have multiple, nested functions.
When we want to declare a variable,
which one do we use, let or const?
What is the different in between them?
In short, let allows to mutate or update the variable
as you please.
While const is immutable, or you can't change
the value once it is initialized.
If we took a look at this variable here,
the warriorsPerPlatoon, because it is a let
we could reassign a number to this variable.
We could say something like, warriorsPerPlatoon
and do 70 instead of 60.
If this was a const, we couldn't do this
and, in fact it would actually return an error
if we did this.
This might be a bit confusing, so let's explore
this further, in code, in the next video.