In JavaScript, when you define an array using literal syntax, the elements of the array can be omitted with additional commas:
a = [1, 2, 3]; // 1, 2, 3 b = [1, , 2, 3]; // 1, undefined, 2, 3
I noticed that when accessing values that the missing values were not “native properties”
b.hasOwnProperty(1); //false
In contrast, if you define an array that explicitly sets undefined , it will be set as a "native property":
c = [1, undefined, 2, 3]; c.hasOwnProperty(1); //true
Is there a behavior to define elements of omitted elements defined in the specification? If so, which spec and where?
(additional bonus) Is it a reliable cross-browser, for example, confirmed by compatibility tables?
source share