USE ESCAPE CODES
Notice the \n in the alert message code in the preceding
example. This is a JavaScript escape code that
creates a new line in the output. All Web programming languages include
escape codes so that special characters can be used. In JavaScript, escape
codes are preceded by a backslash. This tells the JavaScript interpreter that
you want the character(s) following the backslash to be treated in a special
way.
JavaScript escape codes include the following:
- \b: backspace
- \n: new line
- \": double quote
- \': single quote
The escape codes for quotations are the ones you'll use most frequently. Because pairs of quotation marks (either double or single) are used to delineate the beginning and end of strings, you need some way to include quotation marks within strings without causing a premature end to the string. If you want, for example, to quote a word within a string, you would use the following:
alert ("Don't you want to do the \"right\" thing?");
