title: How to include an escaped<script> </script> tag in a JavaScript variable?
body: <p>I have a string in Javascript where I have to escape several characters:</p>
  
  <pre><code>&lt;script&gt;
  function GenerateCode() {
       alert(ctry);
       var script = "&lt;script async src=\"//somesite.com/feed/livetrend.js\"&gt;&lt;/script&gt;";
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>I have tried the following to escape the characters:</p>
  
  <pre><code>var script = "&lt;script async src=\"//somesite.com/feed/livetrend.js\"&gt;&lt;/script&gt;";
  </code></pre>
  
  <p>However, this does not work correctly, despite having taken care of including an escape character <code>\</code> in front of <code>"</code> </p>
  
  <p>It an error -<code>unterminated string constant</code>.</p>