Section 5.9. Special (Escaped) String Characters


5.9. Special (Escaped) String Characters


JavaScript provides a mechanism for including common whitespace characters (sometimes called control codes) inside strings, as well as symbols that otherwise conflict with string representation. The key is the backslash character (\), followed immediately by a single character with a special meaning. The following table shows the recognized escaped characters and their meanings.

Escape sequence

Description

\b

Backspace

\t

Horizontal tab

\n

Line feed (new line)

\v

Vertical tab

\f

Form feed

\r

Carriage return

\"

Double quote "

\'

Single quote `

\\

Backslash


These characters come in handy for alert, confirm, and prompt dialog box text. For example, if you want to display multiple paragraphs with a blank line between them in an alert box, you would insert line feed characters:

 alert("First paragraph.\n\nSecond paragraph.") 

Note that these characters apply to strings, and do not influence HTML content formatting for carriage returns.




Dynamic HTML. The Definitive Reference
Dynamic HTML: The Definitive Reference
ISBN: 0596527403
EAN: 2147483647
Year: 2004
Pages: 120
Authors: Danny Goodman

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net