--

Technically, it is not a surprise. If it instead of 13 you had c, whatever c is:

var b = c

[a, b].forEach(console.debug)

The compiler can interpret c as an object, and thus it can be indexed, and the a, b is the comma operator, so you dismiss a, and get b value as index.

But the grammar does not know the difference between 13 and c, both are an expression, and expressions can be indexed. In fact, almost every expression in JS is an object, and thus it can be indexed.

But of course... that is what machines do, not humans.

--

--

David Rodenas PhD
David Rodenas PhD

Written by David Rodenas PhD

Passionate software engineer & storyteller. Sharing knowledge to advance our skills. Join me on a journey of discovery in the world of software engineering.

No responses yet