Commas in arrays
The specification of Javascript allows for elision - the omission of element values - when initializing an array. While this behavior has a history of browser-specific bugs, it is a useful way to increase array length when used carefully.
The empty space creates a missing element. Notice that an empty space is not created for a trailing comma.
The missing element is not store a null
or undefined
value - it simply isn't there.
The missing space is referred to as a hole. A hole is equivalent to undefined
in comparison, not null
.
The in
operator will report false
when checking for the index of a hole.
In this way, a hole is functionally similar to an element that is out of bounds.
Even assigning the value undefined
to the array will fill the hole.