title: Why does 2 == [2] in JavaScript?
body: <p>I recently discovered that <code>2 == [2]</code> in JavaScript.  As it turns out, this quirk has a couple of interesting consequences:</p>
  <pre><code>var a = [0, 1, 2, 3];
  a[[2]] === a[2]; // this is true
  </code></pre>
  <p>Similarly, the following works:</p>
  <pre><code>var a = { &quot;abc&quot; : 1 };
  a[[&quot;abc&quot;]] === a[&quot;abc&quot;]; // this is also true
  </code></pre>
  <p>Even stranger still, this works as well:</p>
  <pre><code>[[[[[[[2]]]]]]] == 2; // this is true too! WTF?
  </code></pre>
  <p>These behaviors seem consistent across all browsers.</p>
  <p>Any idea why this is a language feature?</p>
  <p>Here are more insane consequences of this &quot;feature&quot;:</p>
  <pre><code>[0] == false // true
  if ([0]) { /* executes */ } // [0] is both true and false!
  
  var a = [0];
  a == a // true
  a == !a // also true, WTF?
  </code></pre>