title: if Not undefined and indexOf ('foo') do something
body: <p>So I'm trying to call where if not undefined and index is foo so I use:</p>
  
  <pre><code>if (typeof(getdata(js, 'box1')) != "undefined" 
  &amp;&amp; (getdata(js, 'box1')).indexOf('foo') &gt;= 0) {
        // Do something
     }
  </code></pre>
  
  <p>This works fine but I dont want to call the getdata twice. Is there way to say if <code>getdata</code> is <strong>not undefined</strong> and the indexOf is foo then do something, without calling the <code>getdata()</code> function twice?</p>