Character constant (Definition)

A literal description of a single character.

Property/method value type:String primitive

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\
\aAudible alert (MSIE displays the letter a)<BEL>
\bBackspace (ignored silently in MSIE)<BS>
\fForm Feed (ignored silently in MSIE)<FF>
\nLine Feed (Newline - MSIE inserts a space)<LF>
\rCarriage Return (MSIE inserts a space)<CR>
\tHorizontal Tab (MSIE inserts a space)<HT>
\vVertical tab (MSIE displays the letter v)<VT>
\0nnOctal escape-
\042Double Quote"
\047Single Quote (Apostrophe)'
\134Backslash\
\xnnHexadecimal escape-
\x22Double Quote"
\x27Single Quote (Apostrophe)'
\x5CBackslash\
\unnnnUnicode escape-
\u0022Double Quote"
\u0027Single Quote (Apostrophe)'
\u005CBackslash\
\uFFFEA special Unicode sentinel character for flagging byte reversed text-
\uFFFFA special Unicode sentinel character-

See also:Character handling, Constant, Constant expression, Escape sequence (\), Literal, Primitive value