Notes
Variables are containers for storing data (storing data values).
We can declare a variable in JavaScript in for ways.
Using var
var x = 2;
Here x stores the value 2.
Using let
let y = 3;
Here y stores the value 3.
Using const
const z = 5;
Here z stores the value 5.
Use nothing
userName ="admin";
Here userName stores the String "admin".
We should always declare JavaScript variables with var
, let
, or const
If you think the value of the variable will not change (General Rule), use const
otherwise use var
or let
.
The constant values cannot be changed.