A character constant in JavaScript is represented by a single character length String primitive. Technically it is a string, not a character. In JavaScript the single quote delimiter encloses strings as well as the double quote delimiter.
Beware of this if you are familiar with C language character constants. In C, the single quote (apostrophe) is used to enclose a single character that can be represented by a byte.
Some character constant escape codes are listed in the following table:
Escape Sequence: | Name: | Symbol: |
\" | Double Quote | " |
\' | Single Quote (Apostrophe) | ' |
\\ | Backslash | \ |
\a | Audible alert (MSIE displays the letter a) | <BEL> |
\b | Backspace (ignored silently in MSIE) | <BS> |
\f | Form Feed (ignored silently in MSIE) | <FF> |
\n | Line Feed (Newline - MSIE inserts a space) | <LF> |
\r | Carriage Return (MSIE inserts a space) | <CR> |
\t | Horizontal Tab (MSIE inserts a space) | <HT> |
\v | Vertical tab (MSIE displays the letter v) | <VT> |
\0nn | Octal escape | - |
\042 | Double Quote | " |
\047 | Single Quote (Apostrophe) | ' |
\134 | Backslash | \ |
\xnn | Hexadecimal escape | - |
\x22 | Double Quote | " |
\x27 | Single Quote (Apostrophe) | ' |
\x5C | Backslash | \ |
\unnnn | Unicode escape | - |
\u0022 | Double Quote | " |
\u0027 | Single Quote (Apostrophe) | ' |
\u005C | Backslash | \ |
\uFFFE | A special Unicode sentinel character for flagging byte reversed text | - |
\uFFFF | A special Unicode sentinel character | - |
Prev | Home | Next |
char | Up | Character display semantics |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |