Strings

Any series of characters between quotes is called a string. (You'll be seeing lots of strings throughout this book.) Strings are a basic type of information, like numbers—and like numbers, you can assign them to variables.

To assign a string to a variable, you'd write something like this:

var my_name = "thau!";

The word thau! is the string assigned to the variable my_name.

You can stick strings together with a plus sign (+), as shown in the bolded section of Figure 2-6. This code demonstrates how to write output to your page using strings.

Putting strings together

Figure 2-6. Putting strings together

Line-by-Line Analysis of Figure 2-6

Line ❶ in Figure 2-6,

var first_part ...

Get The Book of JavaScript, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.