Dealing with Special Characters

The back slash character has special meaning in JavaScript strings. It is an escape character that allows us to enter special characters that would be difficult to enter otherwise.

Now most of my life I have been slash deficient. When someone says forward slash or back slash, I don’t know which character it is. Some have tried to explain it by telling me to imagine a person leaning backwards or forwards. But that doesn’t help me at all because I don’t know which side has the face.

Anyway, I digress. This is a back slash (\). Now we are all on the same page. This character allows escape sequences in strings that can insert special characters. JavaScript has some default escape characters, but the real power begins when you use unicode or hexadecimal character codes. To specify a hexadecimal character enter \x and then the hex code. For unicode, enter \u and then the code.

I think the biggest trick with these charaters is knowing the code to enter to get a certain character. Here are a couple of websites that have unicode and hexadecimal codes for characters:

Once you have a list of codes, most people are good to go. But if you need a little more guidance, here is a recent tutorial on special characters in JavaScript.

Author: Steven Hancock

Steven has 20+ years experience in product development and 15+ years using JavaScript. He started learning JavaScript when it was a niche language used for minor affects on a web site. The growth and ubiquitous nature of JavaScript both excites and inspires him.

Currently he is President and lead Trainer at All Things JavaScript, a resource for anyone and everyone that hopes to increase their JavaScript skills.

Steven was the co-owner of Rapid Intake, an eLearning Authoring firm. While there he managed all development and professional service related activities. He was heavily involved in the initial development of Rapid Intake’s main product, which eventual lead to its acquisition in 2011. In addition to JavaScript, Steve has also dabbled in other web technolgies such as ActionScript, ASP, PHP, HTML, and CSS.