title: Escaping single quotes in JavaScript string for JavaScript evaluation
body: <p>I have a project, in which some JavaScript var is evaluated. Because the string needs to be escaped (single quotes only), I have written the exact same code in a test function. I have the following bit of pretty simple JavaScript code:</p>
  
  <pre><code>function testEscape() {
      var strResult = "";
      var strInputString = "fsdsd'4565sd";
  
      // Here, the string needs to be escaped for single quotes for the eval 
      // to work as is. The following does NOT work! Help!
      strInputString.replace(/'/g, "''");
  
      var strTest = "strResult = '" + strInputString + "';";
      eval(strTest);
      alert(strResult);
  }
  </code></pre>
  
  <p>And I want to alert it, saying: <code>fsdsd'4565sd</code>.</p>