In general, one could say that implicit semi-colon's can easily fail when defining an array on a new line, because an array defined on a new line is interpreted as a property access of the value of the expression on the previous line.
Javascript does only consider new lines to mark the end of a statement if not ending the statement after this new line would cause a parse error. See What are the rules for JavaScript's automatic semicolon insertion (ASI)? and EcmaScript 5 spec for the exact rules. (Thanks to Rob W and limelights)
What happens is the following:
The code get interpreted as
console.log([a,b].length)[a,b].some(function(x){ x.push(x.shift()) });
i.e. all as one statement.
Now parse the statement:
some
is called on the value of console.log([a,b].length)[a,b]
the value of console.log([a,b].length)[a,b]
is computed by taking the returned value of console.log([a,b].length)
(undefined
) and then trying to access the property with the name of the value of a,b
.
a,b
evaluates to the value of b
(try it in your console). There's no property with the value of b
of undefined
, so the resulting value will be undefined
as well.
There's no method some
on undefined
, hence the error.