title: Using object literal rather than switch statement
body: <p>There is a lot of discussions and comments about best practices in <strong>switch</strong> and <strong>if/else</strong> statements. I have seen people saying that <em>we all should use object literal instead of switch</em> when it is possible.</p>
  
  <p>So I've reproduced this case and <a href="http://jsperf.com/switch-from-switches" rel="noreferrer">I went trough a little and simple test</a> between a switch :</p>
  
  <pre class="lang-js prettyprint-override"><code>(function(test){
      var bar;
  
      switch(bar) {
          case 1:
              bar = 'red';
              break;
          case 2:
              bar = 'blue';
              break;
          case 3:
              bar = 'yellow';
              break;
          case 4:
              bar = 'green';
              break;
          case 5:
              bar = 'black';
              break;
      }
  
      return bar;
  })(5);
  </code></pre>
  
  <p>and passing trough an object literal :</p>
  
  <pre class="lang-js prettyprint-override"><code>(function(test){
      return { 1: 'red', 2: 'blue', 3: 'yellow', 4: 'green', 5: 'black' }[ test ];
  })(5);
  </code></pre>
  
  <p>After running this <a href="http://jsperf.com/switch-from-switches" rel="noreferrer">test</a>, it seems evident that the switch statement is faster than calling the tested value in an object literal.</p>
  
  <p>Is my test wrong ? What should I consider before using one or another method in this case ? Or maybe opinionated comments I've seen about this subject are just wrong and I should not try to bypass fundamentals...</p>