Variables
A variable is a named container for a value.
There are three ways to define a variable - var
, let
, and const
. The const
keyword is used for constant values that will not change.
Loading TypeScript...
Changing the value of a const
will produce an error.
TypeScript programs (and most modern JavaScript programs) tend to favor using let
and const
over var
, due
to various unintended behaviors that var
can cause. For example, var
allows a variable to be declared more than once.
Loading TypeScript...
Attempting to use let
to redeclare a variable of the same name will produce an error.