title: myString.replace( VARIABLE, "") ...... but globally
body: <p>How can I use a variable to remove all instances of a substring from a string?
  (to remove, I'm thinking the best way is to replace, with nothing, globally... right?)</p>
  
  <p>if I have these 2 strings,  </p>
  
  <pre><code>myString = "This sentence is an example sentence."
  oldWord = " sentence"
  </code></pre>
  
  <p>then something like this</p>
  
  <pre><code>myString.replace(oldWord, "");
  </code></pre>
  
  <p>only replaces the first instance of the variable in the string.</p>
  
  <p>but if I add the global g like this <code>myString.replace(/oldWord/g, "");</code> it doesn't work, because it thinks oldWord, in this case, is the substring, not a variable. How can I do this with the variable?</p>