0

When I create an array like this in browser console:

var myList = ['home', '',, 'school',,,];

And when I print the value in console by typing myList it gives the result like this:

(6) ["home", "", empty, "school", empty × 2]

As you can see the array index 2 is labeled as empty but when I explicitly type myList[2] it shows it as undefined:

undefined

& if I change its value to undefined and then print it out it changes empty value to undefined:

myList[2] = undefined;
myList
(6) ["home", "", undefined, "school", empty × 2]

I tried to google on this but most of the place claim empty is just a string empty but that is not the case here... the trailing comma in Array isn't assigned any empty string and even in the if condition it only gives a true value if checked against undefined and a false against an empty string ... where the keyword empty itself is not a keyword of JavaScript.

Imran Bughio
  • 4,811
  • 2
  • 30
  • 53
  • you may have a look here: [sparse array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Trailing_commas#Trailing_commas_in_literals) – Nina Scholz Dec 28 '19 at 09:33
  • 1
    javascript has no 'empty' keyword. it doesn't matter what chrome devtools shows you, since that doesn't effect how your program works. – Wali Waqar Dec 28 '19 at 10:04

0 Answers0