Variable: Variables are just like containers that are used to store some values. Values could be anything like string, number, Boolean, and array.
Here we’ll create a variable called myName and assign a value “Papa Programmer”. So let’s see all this in action.
var myName = "Papa Programmer";
Here, myName is a variable name and Papa Programmer is a value. so we can say that now the string “Papa Prgorammer” is stored in myName.
Now lets see how to print a variable’s value in the console.
We can also assign a new value to that same variable name and when we do that, the newly assign value will overwrite the past assigned value.
Here you can see we have first give a value “Papa Programmer” to the variable myName and after that we have reassign the value to “New papa Programmer” and now if we print the variable then the output will be “New papa Programmer” because this new value will overwrite the previous value.
There are some other keywords like const and let which we can use instead of a var while defining the variable name. but there is a difference in these all three which we’ll cover later.