title: How do I replace a double-quote with an escape-char double-quote in a string using JavaScript?
body: <p>Say I have a string variable (<code>var str</code>) as follows-</p>
  <blockquote>
  <p><em>Dude, he totally said that &quot;You Rock!&quot;</em></p>
  </blockquote>
  <p>Now If I'm to make it look like as follows-</p>
  <blockquote>
  <p><em>Dude, he totally said that &quot;You Rock!&quot;</em></p>
  </blockquote>
  <p>How do I accomplish this using the JavaScript <code>replace()</code> function?</p>
  <p><code>str.replace(&quot;\&quot;&quot;,&quot;\\&quot;&quot;);</code> is not working so well. It gives <code>unterminated string literal</code> error.</p>
  <p>Now, if the above sentence were to be stored in a SQL database, say in MySQL as a <em>LONGTEXT</em> (or any other <em>VARCHAR</em>-ish) datatype, what else string optimizations I need to perform?</p>
  <p>Quotes and commas are not very friendly with query strings. I'd appreciate a few suggestions on that matter as well.</p>