title: Javascript switch vs. if...else if...else
body: <p>Guys I have a couple of questions:</p>
  
  <ol>
  <li>Is there a performance difference in JavaScript between a <code>switch</code> statement and an <code>if...else</code>?   </li>
  <li>If so why?</li>
  <li>Is the behavior of <code>switch</code> and <code>if...else</code> different across browsers? (FireFox, IE, Chrome, Opera, Safari)</li>
  </ol>
  
  <p>The reason for asking this question is it seems that I get better performance on a <code>switch</code> statement with approx 1000s cases in Firefox. </p>
  
  <hr>
  
  <p><strong>Edited</strong>
  Unfortuantly this is not my code the Javascript is being produced serverside from a compiled library and I have no access to the code. The method that is producing the javascript is called </p>
  
  <pre><code>CreateConditionals(string name, string arrayofvalues, string arrayofActions)
  </code></pre>
  
  <p>note <code>arrayofvalues</code> is a comma separated list.</p>
  
  <p>what it produces is</p>
  
  <pre><code>function [name] (value) {
    if (value == [value from array index x]) {
       [action from array index x]
    }
  }
  </code></pre>
  
  <p>Note: where <code>[name]</code> = the name passed into the serverside function</p>
  
  <p>Now I changed the output of the function to be inserted into a TextArea, wrote some JavaScript code to parse through the function, and converted it to a set of <code>case</code> statements. </p>
  
  <p>finally I run the function and it runs fine but performance differs in IE and Firefox.</p>