[X]

Holes, Not Undefined

luljs still works

An array can have gaps that its own methods refuse to visit.

In 2026: Still works. A literal like [1, , 3] has a hole, which is not the same as undefined. Its length is 3, but forEach and map skip the hole entirely, and new Array(3) makes three holes, so its map callback never runs. That is why Array(3).fill() exists.

Where it came from: Sparse arrays hold holes that iteration methods skip, distinct from undefined values. MDN's Array page describes sparse arrays. MDN

<script>
var arr = [1, , 3];
document.write('<p><code>[1, , 3].length</code> is <b>' + arr.length + '</b></p>');
var seen = 0; arr.forEach(function () { seen++; });
document.write('<p><code>forEach</code> visited <b>' + seen + '</b> of 3 slots (the hole is skipped)</p>');
var ran = 0; new Array(3).map(function () { ran++; });
document.write('<p><code>new Array(3).map(fn)</code> ran fn <b>' + ran + '</b> times</p>');
</script>
sandboxed demo · breaks nothing but itselfrestart

More in luljs

all 63 in luljs › · the whole library ›