Thursday, June 17, 2010

Programming Tip: Be Care With Quote Syntax

The other day, I was writing a program. It has to display a "\". So obviously, my first instinct was to write that. What I did not remember was that a slash there usually is waiting for some letter to come after it to denote a return or something similar. So, it was taking a quote as that letter. However, a ' " \" ' doesn't actually mean anything so the debugger was getting stuck there. So when you want to write a back slash, you have to click it twice.

Essentially, by doing so you tell the javascript engine that the \ is not denoting a symbol to realize that the \ isn't actually waiting for something like "\n". Alternatively, you could use the special characters ampersand format for a slash: "&#92".

No comments:

Post a Comment

Search This Blog