JavaScript

Escape Characters

JavaScript By ExampleJavaScript provides special characters that allow you to include characters in strings that you cannot normally include - either because it will cause an error or because there is no single character for it. Each of these characters, known as escape characters, begins with a backslash. The backslash is the escape character that tells the JavaScript interpreter that the next character is special.

Escape Sequence

Character

\b

Backspace

\f

Form feed

\n

Line feed (newline)

\r

Carriage return

\t

Horizontal tab

\'

Single quotation mark

\"

Double quotation mark

\\

Backslash

\uHHHH Unicode encoded character (where HHHH is character code)
\### Latin encoded character (where ### is character code)

Notice that because the backslash itself is used as the escape character, you cannot directly type one in your script! If you want to use a backslash, you must type two of them together (\\).

document.write('The path to the file is C:\\program files\\mystuff\\readme.txt.');
document.write('He thought for one moment and then said, "I really didn/'t suspect the problem to be with the hard drive."');

Forgetting to use escape characters properly will result in errors in your JavaScripts.  Take care that you get them right!




Kathie Kingsley-Hughes
Last updated: May 4th 2004
Print This Page   |   Email me when this page changes    |  Search This Site



Crucial.com System Scanner does the work for you!



udes/a_global/close_links.inc"); ?>

Contact Us