var a = 6; a = "String";
Using the arithmetic addition operator on numbers and Strings works differently. When you add two numbers together you get the sum of those numbers, when you add anything to a String then you get the concatenation of the two variables. Concatenation of two variables is like putting one variable on the end of the other, like adding words to the end of a sentence.
var a = 3; var b = 6; var c = "9"; var d = a + b; var e = a + c;
var myBool = true; var another = false;
The final variable type is called ‘null’. A null variable contains nothing, and therefore has no value. The below code shows a variable that is not initialised, this variable has a null value, and contains nothing. You can also assign the null value to a variable, and make it clear that is contains nothing. Logging out the value of ‘a’ will result in the string “undefined” and logging out the variable ‘b’ will result in the string value “null”;
var a; var b = null; console.log(a); console.log(b);
To summarise, variables can be used to store information to be used later in a program. They can be manipulated, or assigned a result from a function such as an addition or concatenation. Also, when adding String variables the result will be a concatenation rather than a normal mathematical sum, even if only one of the variables is a String.