title: Format string template with variables in Javascript
body: <p>I want to use a statically defined template for URL building. </p>
  
  <p>I'm trying to use ES6 string interpolation feature for this</p>
  
  <pre><code>var template = "http://example.com/?name=${name}&amp;age=${age}";
  
  var name = "John";
  var age = "30";
  
  var url = `${template}`;
  </code></pre>
  
  <p>Expected result: <a href="http://example.com/?name=John&amp;age=23" rel="noreferrer">http://example.com/?name=John&amp;age=23</a></p>
  
  <p>Actual result: <a href="http://example.com/?name=" rel="noreferrer">http://example.com/?name=</a>${name}&amp;age=${age}</p>
  
  <p>In case this can't be done with string interpolation is there any better method than <code>String.prototype.replace</code> like</p>
  
  <pre><code>var url = template.replace(/\${name}/,"John").replace(/\${age}/, 23);
  </code></pre>