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.

3
  • check out escape characters in JavaScript... Commented Aug 12, 2015 at 3:39
  • Escaping a backslash `\` is useful but it's generally bad practice to name an object property that. Commented Aug 12, 2015 at 3:40
  • How to escape Backslash in Javascript object literal Commented Aug 12, 2015 at 4:10

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

Comments

1

Just add an other slash '\' before it.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.