ES6 introduced the keywords let
and const
that enable us to declare variables much easier.
Previously, variables declared with var
are function scoped, so if we declare them inside a for
loop they will be available outside of the loop.
Variables declared with let
and const
are block-scoped, which means they are only accessible within the block where they were declared.
So, if we declare a variable with let
, it does not change its value in the outer scope.
const
is similar, but the value of variables declared with this keyword cannot change through reassignment.