Desmond DallasPro Student 395 Points
Can someone answer this for me please.
Why in the alert function why would you put (name + "Sam" + age); Why wouldnt you just put Sam is 26?
Var name = "Sam" var name = "26" alert(name + " Sam " + age);
Steven Parker81,738 Points
Perhaps a bigger question is if
name = "Sam", why would you put
name + "Sam"? Won't that be redundant?
But the reason you would put
"Sam" + age" instead of
"Sam is 26" is that it allows you to display a different age just by changing the value of the variable. I know it doesn't seem like a big deal in this simple example, but in more practical programming situations you will often need to display a variable instead of something permanent in a string.