Had an error in some code this morning but I was curious as to why this parses at all.
How does this code parse?
It is missing a comma on the forth and fifth line.
var board = [
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0]
[0, 'x', 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0]
]
Edit: It returns:
[
[0,0,0,0,0],
[0,0,0,0,0],
undefined
]
My question is why does this parse, and why does undefined appear as the third element in the array?
If this is a duplicate, question can you post a link to the duplicate below.
ANSWER: The answer is: this evaluates to an array [0, 0, 0, 0, 0, 0] and the line after acts as an index lookup on that array.
For example: array[0, 'x', 0, 0, 0, 0]
which then returns undefined