1

If you do

alert("\fan")

It doesn't print \fan. How do I make it so it prints it?

PS: This is like r"\fan" in python.

3 Answers3

2

The Javascript version of r"..." is String.raw`...` :

alert(String.raw`\fan`)
georg
  • 211,518
  • 52
  • 313
  • 390
0

The backslash is used to escape special characters. If you want to use a literal backslash, a double backslash has to be used.

alert("\\fan")
Spectric
  • 30,714
  • 6
  • 20
  • 43
-1

You have to escape the \ character with \\.

alert("\\fan")
Scott Marcus
  • 64,069
  • 6
  • 49
  • 71