Unicode Strings
Emoji, accents, and other Unicode text can make string length and equality more surprising than they look on screen.
Unicode is the international standard that maps numbers to characters. JavaScript strings store Unicode text, but what users see as one character can take more than one internal unit.
The .length property counts internal 16-bit units, not visible characters. Most everyday letters count as one unit. Some emoji need two, so a single visible emoji can report a length of 2.
const emoji = "š";
console.log(emoji.length); // 2, not 1
console.log([...emoji].length); // 1The letter Ć© can be stored as one combined character or as e plus a separate accent mark. Both forms look the same, but === compares the internal units. normalize() converts text to a consistent form before comparison.
const a = "Ć©"; // composed form
const b = "eĢ"; // "e" plus combining accent
console.log(a === b); // false
console.log(a.normalize() === b.normalize()); // trueIn production
Any string you truncate for a UI label, store in a character-limited column, or split on "characters" needs Intl.Segmenter or a grapheme-cluster library. A grapheme cluster is what a user perceives as one character. A naive .slice(0, 10) can cut an emoji sequence in half and write broken text.