0

'\'

Uncaught SyntaxError: Invalid or unexpected token

So how am I to ask if a backslash is equal to a backslash?

if(string[5]=='\'){}

or

string.indexOf('\')

Ben Muircroft
  • 2,936
  • 8
  • 39
  • 66
  • The backslash is an escape character, so you need to escape the escape, to give: `(string[5] == '\\')` – David Thomas May 29 '22 at 22:42
  • Does this answer your question? [JavaScript backslash (\‌) in variables is causing an error](https://stackoverflow.com/questions/3903488/javascript-backslash-in-variables-is-causing-an-error) – snwflk May 29 '22 at 22:43

0 Answers0