3.2.1 String Literals
the string within a matched pair of single or double quotes (' or "). Double-quote
characters may be contained within strings delimited by single-quote characters, and
single-quote characters may be contained within strings delimited by double quotes.
Here are examples of string literals:
"" // The empty string: it has zero characters
"Wouldn't you prefer O'Reilly's book?"
"This string\nhas two lines"
"π is the ratio of a circle's circumference to its diameter"
In ECMAScript 3, string literals must be written on a single line. In ECMAScript 5,
however, you can break a string literal across multiple lines by ending each line but the
last with a backslash (\). Neither the backslash nor the line terminator that follow it
are part of the string literal. If you need to include a newline character in a string literal,
use the character sequence \n (documented below):
"two\nlines" // A string representing 2 lines written on one line
"one\ // A one-line string written on 3 lines. ECMAScript 5 only.
Note that when you use single quotes to delimit your strings, you must be careful with
English contractions and possessives, such as can’t and O’Reilly’s. Since the apostrophe
is the same as the single-quote character, you must use the backslash character (\) to
“escape” any apostrophes that appear in single-quoted strings (escapes are explained
in the next section).
uses either single or double quotes to delimit its strings. Thus, when combining Java-
other style for HTML. In the following example, the string “Thank you” is single-
HTML event-handler attribute:
<button onclick="alert('Thank you')">Click Me</button>