We can easily describe variables as containers for storing data.
There are several ways through which we can define variables in javascript; either automatically or by using the var, let or const keywords.
Let us have a look at some examples:
In this case, the variables will get declared as variables automatically:
//Creating a variable named x and storing the value 20 in it
x=20;
//creating a variable named y and storing the value 30 in it
y=30;
//creating the variable z and storing the sum of variable x and variable y in it
z=x+y;
In this case we are using the var keyword
//Creating a variable named myAge using the var keyword and storing the value 27 in it
var myAge=27;
//Creating a variable named herAge using the let keyword and storing the value 25 in it
let herAge=25;
//Creating a variable named myAge, herAge and OurTotalAge and storing the sum of variable herAge and myAge in the variable OurTotalAge
const herAge=25;
const myAge=27;
const OurTotalAge=herAge+myAge;