[X]

Emoji Break .length

luljs still works

A single emoji reports a length of two.

In 2026: Still works. A string's length counts UTF-16 code units, and characters outside the basic range, like most emoji, take two units each. So the length of one emoji is 2. Spreading the string with [...str] iterates by code point and gives 1. String indexing splits the emoji into unusable halves.

Where it came from: JavaScript strings are UTF-16, so astral characters span two code units. Mathias Bynens's "JavaScript has a Unicode problem" is the definitive treatment. Mathias Bynens

<script>
document.write('<p><code>"\u{1F600}".length</code> is <b>' + "\u{1F600}".length + '</b></p>');
document.write('<p><code>[..."\u{1F600}"].length</code> is <b>' + [..."\u{1F600}"].length + '</b></p>');
document.write('<p>length counts UTF-16 code units; the emoji takes two of them.</p>');
</script>
sandboxed demo · breaks nothing but itselfrestart

More in luljs

all 63 in luljs › · the whole library ›