DEV Community

Discussion on: JavaScript Jungle: Curious case of sparse array in JS

Collapse
 
ranemihir profile image
Mihir Rane

I've been coding with javascript for a long time but didn't know about this at all. Thanks for broadening my knowledge!

More questions:

  1. Why are they called 'sparse'? What exactly is the meaning of that word?
  2. Is 'empty' a data type similar to 'undefined'? What Is the output of (empty == undefined)?

Looking forward to more such articles.

Collapse
 
thejsdeveloper profile image
Vikas yadav • Edited

Thank you for reading. 😊 I am not sure about exact reason to name it like this. I guess because arrays are supposed to be contiguous and sparse means scattered that's why they are called sparse.

To answer your second question. Empty is not a data type. And this hole is represented as empty in chrome browser. I think safari has different way to show this.

Collapse
 
ranemihir profile image
Mihir Rane

Oh I see. Thanks for your help! :)