We should use const
by default to declare all variables. However, if we know that the value of the variable needs to be changed later, we need to declare the variable using the let
keyword.
In the above example:
When declaring a variable using the let
keyword, it is not necessary to assign it a value. We can assign a value to let
after it is declared.
It is important to note that, until a value is assigned to the variable declared using let
, it will contain the value undefined
.
We will learn more about undefined
in another section.