JavaScript Variables
Variables are containers for storing data in JavaScript.
JavaScript Variables can be declared in 4 ways:
Automatically
Using var
Using let
Using const
Automatically
They are automatically declared when first used:
x = 5;
y = 10;
z = x + y;
Using
var
The var keyword was used in all JavaScript code with the old browser.
Example:
var carName
Using
let
It is used only if you can’t use
const
Example:
let carName = “volvo”;
Using
const
It is used if the data type is not changing i.e (Arrays and Objects)