Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 161
  • Last Modified:

/" in JavaScript

In php if I want to store " I can use /" to tell php that it's not the string escape. Is there an equivalent in JavaScript?
1 Solution
in javascript you can use \".
However, please note that you can use this as an alternative:
string s1 = 'testing "quoted text" in a string variable';
string s2 = "testing \"quoted text\" in a string variable";

Open in new window

The s1 and s2 variables will contain exactly the same text.
The single quotes and double quotes are interchangeable. If you want to embed a double quote inside a string literal you can use single quotes on the outside
I believe you mean \"
It's the same escape char in Javascript : \

var words = "He say \"Yes, I will do it !!!\"";

Open in new window

Or just use simple quote :
var words = 'He say "Yes, I will do it !!!"';

Open in new window

Be aware that if you "store" escaped characters, you might need to escape them again later. I.e., if you store an escaped character in a .properties file and retrieve it later, it can need to be re-escaped before it is stored again after, say, a change is made to that property. Handling strings that contain escaped characters can be tricky. I've seen it be a painful thing to fix.


Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now