October 5, 1999 - Escape Sequences | WebReference

October 5, 1999 - Escape Sequences

Yehuda Shiran October 5, 1999
Escape Sequences
Tips: October 1999

Yehuda Shiran, Ph.D.
Doc JavaScript

Strings often include escape sequences, sometimes called escape characters, special characters, or control characters. Escape sequences are usually used to express nonprintable characters, but other special purposes also exist. The following table outlines the escape sequences:

Escape SequenceMeaning
\dddoctal byte (3 digits: ddd)
\xddhexadecimal byte (2 digits: dd)
\'single quote
\"double quote
\fform feed
\nnew line
\rcarriage return
\thorizontal tab

Be sure to use these inline characters only when needed. The behavior of some of them is not so intuitive. The carriage return escape sequence, for example, creates a new line only in dialog boxes and text areas.

Here are some strings that use these escape sequences:

"\x2499.99" // $99.99 (the hex value of the $ character is 24)
'c:\\games\\sc2000\\' // c:\games\sc2000\
'Let\'s learn JavaScript...' // Let's learn JavaScript...