JavaScript backslash (\) in variables is causing an error

Viewed 216877

In Javascript, when I put a backslash in some variables like:

var ttt = "aa ///\\\";
var ttt = "aa ///\"; 

Javascript shows an error.

If I try to restrict user in entering this character, I also get an error:

(("aaa ///\\\").indexOf('"') != -1)

Restricting backslashes from user input is not a good strategy, because you have to show an annoying message to the user.

Why am I getting an error with backslash?

5 Answers
Related