Useful Resources
syllabus | schedule | exercises | assignments | class notes | resources | students | ARTC courses
Variables

Javascript Variables & Variable concatenation

Concatenation: the operation of joining two or more character strings end to end.

To join two strings together, we use the + (plus) symbol.
<head>
      <script>
            var name = "John" + "Doe";
            alert(name);
      </script>
</head>
This will alert "JohnDoe".

It's a little pointless to concatenate to non-variable strings together, as you could just do this:
var name = "John Doe";

Usually concatenation is used when you have variables:
var first = "John";
var last = "Doe";
var name = first + " " + last;
alert(name);
This will echo "John Doe";

You can also add strings to the end of a variable with "+=":
var sentence = "John Doe";
var sentence += " is so awesome!";
alert(sentence);
This will echo "John Doe is so awesome!";

[BACK to RESOURCES]