CHAPTER 5

image

Strings

A string consists of a series of characters delimited by either double quotes or single quotes. Which notation to use is a matter of preference.

var s1 = "Hello";var s2 = ’ World’;

There are two operators that can operate on strings. For combining strings there is the plus sign (+), which is called the concatenation operator in this context. It has an accompanying assignment operator (+=) that appends a string to the end of a string variable.

var greeting = s1 + s2; // "Hello World"s1 += s2; // "Hello World"

To break a line within a string, a backslash must be added. This character escapes the newline character that in JavaScript ...

Get JavaScript Quick Syntax Reference 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.