let age = 72;
In the above example, we have two variables “hens” which have a value of four and “roosters” which has a value of two. We added them together by recalling them again. We are not recalling them here but also give a nice name. A way of understanding what it is? We can see clearly we are adding hens to roosters and trying to calculate the total number of chickens.
The main reasons for variables are here that we are storing information so, that recall it and use it later on. So, hens + roosters give us the result 6.
let hens = 4; let roosters = 2; hens + roosters //6
Update Values of Variables
In the above figure, I have four hens but a raccoon killed a hen which is very sad. So, we have to remove the killed one hen from our variable “hens”. You can see in the above figure that remove the 1 hen from the variable “hens” by using the negative sign (-) but it not changed the value of variables “hens”.
So, we can update the value of “hens” variable like this:
let hens = 4; hens – 1; // this does not change the value of variable hens. hens = hens – 1; // this will change the value of hens variable to 3. hens // 3 Now the hens variable has value of 3.
In the above figure, we just updated the value of the “hens” variable by setting the “hens” variable equal to the variables current value which is four, and then we subtracted one from it by using the negative sign.