title: JavaScript replace is not working if second argument is again a replace method
body: <p>I am playing with JavaScript string function and was trying to replace a string like below</p>
  
  <pre><code>Actual String : 'Microsoft' 
  Replace with :  '\'$\'' is not defined
  </code></pre>
  
  <p>I tried a simple replace like</p>
  
  <pre><code>"Microsoft".replace("Microsoft","\'$\' is not defined");
  </code></pre>
  
  <p>and it results</p>
  
  <pre><code>' is not defined.
  </code></pre>
  
  <p>But I want to preserve $ sign so thought to write another function which will preserve the $ and return the string; and the same string would be the second parameter for the actual replace method.</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;body&gt;
  
  
  
  &lt;p id="demo"&gt;Microsoft&lt;/p&gt;
  &lt;p id="test"&gt;&lt;/p&gt;
  
  &lt;button onclick="myFunction()"&gt;Try it&lt;/button&gt;
  
  &lt;script&gt;
  function stripslashes(str) {
      str=str.replace("/\\'/g",'');
      return str;
  }
  function myFunction() {
      var newStr = stripslashes('\'$\' is not defined.');
      var res = "Microsoft".replace("Microsoft",newStr);
      document.getElementById("demo").innerHTML = res;
      document.getElementById("test").innerHTML = newStr;
  }
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>But it is not working, can anyone help me with it ?</p>