function lastZ() {
var strCopy = document.myform.mystring.value;
var lastIndex = strCopy.length - 1;
if ( strCopy.charAt(lastIndex) == "Z") {
document.bgcolor="blue";
}
}
var X = 7;
for (i=2; i<5; i++) {
X += i;
}
X initially has the value 7. The loop changes the value of i from 2 to 3 to 4, each time adding that value to X. The final value of X is 16.var X = 4; var Z = "6"; var Y = "X" + Z;In the last statement, "X" is a literal string which has nothing to do with the variable X. Y has the value "X6".