In JavaScript, there are two ways to declare a variable - using the var
keyword or the let
keyword.
Here is an example of declaring a variable using the var
keyword:
index.tsx14 chars2 lines
In this example, we declared a variable named num
and assigned it a value of 10
.
Here is an example of declaring a variable using the let
keyword:
index.tsx30 chars2 lines
In this example, we declared a variable named greeting
and assigned it a value of "Hello World"
.
Note that the difference between var
and let
lies in their scoping rules. var
has function scope while let
has block scope.
gistlibby LogSnag