Did you find this useful?
Socialize it today.

JavaScript Special Characters

Wednesday, April 18, 2012

Just about every programming language has a list of special characters. These are characters that have a special purpose. JavaScript is no different. In JavaScript you can add special characters to a text string by prefixing the string with the backslash character.

in the following example, we will see how the use of special characters are needed to properly display a message.

var txt="Did you read that really "cool" book?";

In JavaScript single or double quotes are used to store the value of a string. Since we placed quotes around the word cool, the full string value is not assigned to the variable. If we require the quotes in our output, we need to use special characters in our code. Here is how we would address that need.

var txt="Did you read that really \"cool\" book?";

The following is a list of the most common special characters that you will be using when working with JavaScript code. Aside from the single and double quotes, the new line special character is also very common.

\'Single quote
\"Double quote
\fForm feed
\nNew line
\rCarriage return
\vVertical tab

Please help us spread the word by socializing it today!

email contact us

Did you find something wrong with the information on this page? Please take a moment to report it to us so that we can continue to improve the quality of the information on this site. Click here to report an issue with this page.

Recommended Books & Training Resources

Murachs JavaScript and DOM Scripting JavaScript and jQuery: The Missing Manual Professional JavaScript for Web Developers