title: Javascript: What's more efficient, IF block or TRY/CATCH?
body: <p>I'd love some other opinions on what's more efficient in this code. Basically in the following code, there's a setInterval loop and I need 4 requirements to be true before the code runs in the loop. So in v.1 I wrote an if statement checking all 4. Worked fine.</p>
  
  <p>Then I switched to just using try/catch, with the code I want to execute sitting in try{}. The logic was that during each loop, an exception would be generated but suppressed for each invalid condition. On the final loop where all conditions are true, the code executes and clears the interval.</p>
  
  <p>Either works. I like the try/catch method because there's less conditional code that I need to write and worry about breaking. But I'm worried that try/catch is really inefficient, especially in a setInterval() loop hitting at 100ms. What are some opinions of other bright minds here on SO?</p>
  
  <p><b>Try/Catch</b></p>
  
  <pre><code>var intvar = setInterval(function(){
  try{    
      clearInterval(intvar);
  
      jQuery('#'+nav[pageid].t1+'&gt;a').replaceWith(jQuery('&lt;span&gt;'+jQuery('#'+nav[pageid].t1+'&gt;a').text()+'&lt;/span&gt;'));
  
      //set display classes for nav
      jQuery('#'+nav[pageid].t1).addClass('selected').find('#'+nav[pageid].t2).addClass('subselect'); //topnav
      jQuery('#'+nav[pageid].t3).addClass('selected').find('#'+nav[pageid].t4).addClass('subselect'); //leftnav
  }catch(err){}
  },100);
  </code></pre>
  
  <p><b>IF Block</b></p>
  
  <pre><code>var intvar = setInterval(function(){
  
  if(typeof jQuery == 'function' &amp;&amp; typeof nav == 'object' &amp;&amp; typeof pageid != 'undefined' &amp;&amp; typeof document.getElementById('leftnav') == 'object'){
      clearInterval(intvar);
      jQuery('#'+nav[pageid].t1+'&gt;a').replaceWith(jQuery('&lt;span&gt;'+jQuery('#'+nav[pageid].t1+'&gt;a').text()+'&lt;/span&gt;'));
  
      //set display classes for nav
      jQuery('#'+nav[pageid].t1).addClass('selected').find('#'+nav[pageid].t2).addClass('subselect'); //topnav
      jQuery('#'+nav[pageid].t3).addClass('selected').find('#'+nav[pageid].t4).addClass('subselect'); //leftnav
  }
  
  },100);
  </code></pre>