Variables and Expressions
var x = 6; var y = 3; var z = x + y; x = x + 1; y = y + 1; var a = x + y;
At the end of this group of statements, the variable z is equal to (contains) 9; a is equal to 11.
var a = "inter"; var b = "mediate"; var c = a + b;
At the end of this group of statements, the variable c is equal to the text string "intermediate." This process of joining text strings is called concatenation . Variables can be concatenated with each other and with other text strings, like this:
var d = "Fred"; var e = "Barney"; var f = d + " and " + e;
At the end of this group of statements, the variable f is equal to the text string " Fred and Barney ". The word and , as well as the spaces on either side of this word, are contained in the text string that is joined to, or concatenated with, the two variables.
Practice Session #2
In this exercise, you'll build on the practice file you created in the previous exercise, using variables to construct the message that appears in the alert window.