title: JavaScript switch case using enum
body: <p>I have an "enum" declared like so:</p>
  
  <pre><code>var PlaceType = {
          PASSABLE_TERRAIN: 1,
          IMPASSABLE_TERRAIN: 0,
          SOMEWHAT_PASSABLE_TERRAIN: 2,
          PATH: 3
      };
  </code></pre>
  
  <p>and a function declared like this:</p>
  
  <pre><code>setPlaceType(placeType) {
          this.clear = false;
          this.placeType = placeType;
  
          alert("before switch "+(PlaceType.SOMEWHAT_PASSABLE_TERRAIN==this.placeType));
          switch(this.placeType) {
          case PlaceType.PASSABLE_TERRAIN: {
              alert("Case PASSABLE");
              break;
          }
          case PlaceType.IMPASSABLE_TERRAIN: {
              alert("Case IMPASSABLE");
              break;
          }
          case PlaceType.SOMEWHAT_PASSABLE_TERRAIN: {
              alert("Case SOMEWHAT_PASSABLE");
              break;
          }
          case PlaceType.PATH: {
              alert("Case PATH");
              break;
          }
          default: {
              alert("case default");
          }
          }
      }
  </code></pre>
  
  <p>if I call it like this:</p>
  
  <pre><code>setPlaceType(1);
  </code></pre>
  
  <p>I get the following alerts: "before switch true", "case default"</p>
  
  <p>if I call it like this:</p>
  
  <pre><code>setPlaceType(2);
  </code></pre>
  
  <p>I get the following alerts: "before switch false", "case default"</p>
  
  <p>In other words, the function is called with the proper argument, which, when doing (what it seems to me to be) the same comparison as the switch but via "==" I get correct behavior, but the switch never matches the values to the appropriate case. Does anybody know why?</p>