title: Programmatically construct a condition for use in an if() statement
body: <p>Let's assume for a moment that I have something like this:</p>
  
  <pre><code>if (document.getElementById('div1').innerHTML &amp;&amp;
      document.getElementById('div2').innerHTML &amp;&amp;
      document.getElementById('div3').innerHTML &amp;&amp;
      document.getElementById('div4').innerHTML &amp;&amp;
      document.getElementById('div5').innerHTML &amp;&amp;
      ...
      document.getElementById('div100').innerHTML)
  </code></pre>
  
  <p>Obviously typing out and maintaining a big conditional statement like this is problematic.</p>
  
  <p>I would like some solution like:</p>
  
  <pre><code>var conditional = "";
  for(var i = 1; i &lt;= 100; i++){
    conditional += "document.getElementById('div" + i +"').innerHTML";
    if(i &lt; 100) {
      conditional += " &amp;&amp; ";
    }
  }
  if(interpretStringAsJSExpression(conditional)){
      console.log("all my divs have content");
  }
  </code></pre>
  
  <p>Is something like this possible in JavaScript?</p>
  
  <p>Great answers have been submitted, and I am sure that I and others will benefit from them. However, purely from a place of curiosity, is it possible to store and run JavaScript expressions or commands in strings?</p>
  
  <p>Like I have proposed in my example: <code>interpretStringAsJSExpression(conditional)</code></p>