JavaScript Kit > JavaScript Reference > Here
String escape sequences
Created: July 23rd, 2006
Escape sequences allow you to parse string literals in JavaScript for special characters/ formatting, such as newlines within a TEXTATEA's input. Below lists these escape sequences:
Escape sequences
Properties | Description |
---|---|
\b | Backspace. |
\f | Form feed. |
\n | Newline. |
\O | Nul character. |
\r | Carriage return. |
\t | Horizontal tab. |
\v | Vertical tab. |
\' | Single quote or apostrophe. |
\" | Double quote. |
\\ | Backslash. |
\ddd | The Latin-1 character specified by the three octal digits between 0 and 377. ie, copyright symbol is \251. |
\xdd | The Latin-1 character specified by the two hexadecimal digits dd between 00 and FF. ie, copyright symbol is \xA9. |
\udddd | The Unicode character specified by the four hexadecimal digits dddd. ie, copyright symbol is \u00A9. |
Examples
Adding newlines (line breaks) when alerting text
alert("Welcome to JavaScript Kit\nEnjoy your stay!")
Adding quotes within a string
var myquote="George said \"Life is like a box of chocolates\""
Examining the contents of a TEXTAREA, line by line
<textarea id="holder">
This is line 1
This is line 2
This is line 3
</textarea>
<script type="text/javascript">
var containertext=document.getElementById("holder").value.split("\n")
//Store each line of textarea as array element
alert(containertext[2]) //alerts "This is line 3
</script>
Reference List
- JavaScript Operators
- JavaScript Statements
- Global functions
- JavaScript Events
- Escape Sequences
- Reserved Words
Right column