• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 5. Building JavaScript Expressions > Building String Expressions

Building String Expressions

A string expression is an expression where at least one of the operands is a string, and the result of the expression is another string. String expressions are straightforward in the sense that there is only one operator to deal with: concatenation (+). You use this operator to combine (or concatenate) strings within an expression. For example, the expression "Java" + "Script" returns the string "JavaScript". Note, however, that you can also use strings with the comparison operators discussed in the next section.

Tip

I mentioned back in Chapter 2, "Creating Your First Scripts," that all your JavaScript statements should appear on a single line. The exceptions to that rule are long expressions, which you can break into multiple lines as long as the break occurs immediately before or after an operator. With a string expression, for example, you can display it on multiple lines as long as the break occurs immediately before or after the + operator, as in the following examples:

       var message1 = "How did the fool and his money " +
                      "get together in the first place?"
       var message2 = "Never put off until tomorrow that which you "
                    + "can put off until the day after tomorrow."



PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint