Variables
Variables are used to store values, they act as containers.
x = 5;
Value 5
is stored in x
.
var x = 5;
x
is declared as variable, and value of 5
is assigned to it. x
can be redeclared in the same block.
const x = 5;
x
is declared a constant, and the value once assigned, cannot be changed.
let x = 5;
x
is assigned a value of 5
, and the x
cannot be redeclared in the same block-scope.
a = 4;
b = 2;
c = a + b;
Variables can be used in expressions like a + b
. Values of a
, and b
are substituted in place of them.