1

How do I set a \ as a string in JavaScript I am using it like this

Var x = {"\":"some value"} 

But it's says that that is illegal, so then I tried it like '\' this but still the same error happened.

royhowie
  • 11,075
  • 14
  • 50
  • 67
Mason Wright
  • 357
  • 1
  • 3
  • 11

2 Answers2

3

You can use escaping characters so add one more \ it will be escaped and become a string like this var x = {"\\":"some value"}

nikoss
  • 3,254
  • 2
  • 26
  • 40
1

Just add an other slash '\' before it.

Avishay Matayev
  • 119
  • 1
  • 8