No semicolon before [] is causing error in Javascript?
<pre><code>var a = [1,2,3,4];
var b = [10,20,30,40];
console.log([a,b].length)
[a,b].some(function(x){ x.push(x.shift()) });
</code></pre>

<p>I was extremely surprised today when this code caused</p>

<pre><code>[a,b].some(function(x){ x.push(x.shift()) });
      ^
TypeError: Cannot call method 'some' of undefined
</code></pre>

<p>Obviously the JavaScript 'auto semicolon insertion' is not working as expected here. But why?</p>

<p>I know you might recommend to use <code>;</code> everywhere to avoid something like that, but the question is not about whether it is better to use <code>;</code> or not. I would love to know what exactly happens here?</p>
