Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Special Characters (JavaScript)

JavaScript provides escape sequences that you can include in strings to create characters that you cannot type directly.

A string value is a series of zero or more Unicode characters (letters, digits, and other characters). String literals are enclosed in matching pairs of single or double quotation marks. Double quotation marks can be contained in a string that is enclosed in single quotation marks. Single quotation marks can be contained in a string that is enclosed in double quotation marks.

Each character in a string literal can be represented by an escape sequence. An escape sequence starts with a backslash (\) that informs the JavaScript interpreter that the next character is a special character.

You can specify a Unicode character by using the \uhhhh escape sequence, where hhhh is a four-digit hexadecimal number. A Unicode escape sequence can represent any 16-bit character.

You can use a single-character escape sequence for some characters. For example, \t specifies a tab character.

The following table lists escape sequences for several characters.

Unicode character value

Escape sequence









White space



Line feed (new line)

Line terminator



(See note after this table.)

Vertical tab

White space



Form feed

White space



Carriage return

Line terminator



White space



Double quotation mark (")



Single quotation mark (')



Backslash (\)


Nonbreaking space

White space


Line separator

Line terminator


Paragraph separator

Line terminator


Byte order mark

White space

The Category column specifies whether the character is a white space or line terminator character. The trim Method (JavaScript) removes leading and trailing white space and line terminator characters from a string.

The backslash itself is used as the escape character. Therefore, you cannot directly type one in your script. If you want to write a backslash, you must type two of them together (\\).


Starting in Internet Explorer 9 standards mode, you cannot identify the browser as Internet Explorer by testing for the equivalence of the vertical tab (\v) and the "v". In earlier versions, the expression "\v" === "v" returns true. In Internet Explorer 9 standards mode, the expression returns false.


The following example demonstrates the \\ and \' escape sequences.


document.write('The image path is C:\\webstuff\\mypage\\gifs\\garden.gif.');
document.write ("<br />");
document.write('The caption reads, "After the snow of \'97. Grandma\'s house is covered."');
© 2015 Microsoft