title: Concatenating strings with `if` statements in JavaScript
body: <p>I'm attempting to set up a script to concatenate some variables inside a string <em>if they exist</em>, in order to place the appropriate metadata tags into a rendered HTML document.</p>
  
  <p>My concatenation code is:</p>
  
  <pre class="lang-js prettyprint-override"><code>data = "&lt;html&gt;\n&lt;head&gt;\n" + "&lt;/head&gt;\n&lt;body&gt;\n\n" + paras.join("\n\n") + "\n\n&lt;/body&gt;\n&lt;/html&gt;";
  </code></pre>
  
  <p>I'm trying to add <code>if</code> statements like the following into it (between the first and second items):</p>
  
  <pre class="lang-js prettyprint-override"><code>if (typeof metadata_title !== "undefined") {
      "&lt;title&gt;" + metadata_title + "&lt;/title&gt;\n"
  }
  if (typeof metadata_author !== "undefined") {
      "&lt;meta name=\"author\" content=\"" + metadata_author + "\"&gt;&lt;/meta&gt;\n"
  }
  if (typeof metadata_date !== "undefined") {
      "&lt;meta name=\"date\" content=\"" + metadata_date + "\"&gt;&lt;/meta&gt;\n"
  }
  </code></pre>
  
  <p>But I can't add any of these statements directly into the concatenation code 
  (it throws an error: <code>Unexpected token (</code>).</p>
  
  <p>How best would I go about adding statements such as these into my concatenation string?</p>