Why the Family Emoji Counts as 11 Characters in JavaScript
A word counter bug revealed that the family emoji π¨βπ©βπ§βπ¦ was counted as 11 characters even though users see only one. The article compared four counting methods across seven strings, namely UTF-16 length, code points, grapheme clusters, and UTF-8 bytes, and found that only plain English and Roman Urdu stayed consistent. The mismatch happens because JavaScript's default length counts UTF-16 code units, while many visible characters are built from several joined code points. The author recommends Intl.Segmenter for user-facing limits, with a code point fallback for older browsers, and suggests UTF-8 byte counts for storage and API constraints.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.


Discussion (0)
Log in to join the discussion and vote.
Log in