One of the fundamental tasks handled by programming languages is to temporarily store and manipulate bits of data in memory, mostly strings and numbers, but often also dates and other special data types, called values. One of the defining characteristics of a programming language is the data types it supports and the features it has for working with those types. A language’s types define the kinds of values you can represent and work with. When you need to save a value for later use in the program, you can define a variable and store the value in it. A variable is a symbolic name for the value that you store in memory, and lets you refer to the value by name and, over the course of program execution, assign different values to the same variable.
Escape Sequences in String Literals
When you need to include any of a number of characters that have special meaning within a string literal, you can create an escape sequence using a backslash to identify the special character. For example, if you absolutely must include the type of quote used as a string delimiter within the string, you can create an escape sequence as in the following string literal. By making it an escape sequence, the single quote will appear within the string, even though that is also the string delimiter.
<span style="color: #a30000; font: courier; margin-left: auto; margin-right: auto;">'"Don't use that food to feed the dog," she said. "It's
been recalled by the manufacturer."</span>
The following code demonstrates some of these escape sequences. Some lines are broken in random places to fit on the page, but each console.log statement should appear on a single line in a code file. Figure 3 shows the results in the Console panel.
<span style="color: #a30000; font: courier; margin-left: auto; margin-right: auto;">console.log('"Don't use that food to feed the dog," she
said. "It's been recalled by the manufacturer."');
console.log("tStart this line indented a bit.");
console.log("The backslash (\) character is the escape
console.log("You can use the newlinenescape sequence
(\n) to break anstring over multiple lines.");
console.log("The copyright symbol is xa9 and pi is
Figure 3. The results in the Console panel of running sample escape sequence code.