Menu

How Emoji Work Under the Hood: Code Points, ZWJ Sequences and Why String Length Lies
πŸ“°

How Emoji Work Under the Hood: Code Points, ZWJ Sequences and Why String Length Lies

DEV Community: javascriptΒ·Ling ChenΒ·4 days ago
#5jX2dr2p
#devtojavascript#devto#dev#emoji#code
Reading 0:00
15s threshold

Emoji look simple: one little picture. For developers, they are one of the most common sources of subtle bugs, such as truncated messages, broken character counters, mangled database rows and cursor positions that jump. This post explains how emoji are encoded and how to handle them correctly.

Emoji are Unicode characters, sometimes several

Each basic emoji has a Unicode code point . πŸ˜€ is U+1F600 ("grinning face"), and πŸ’€ is U+1F480 ("skull"). These code points live outside the Basic Multilingual Plane, which already causes trouble in languages that use UTF-16 internally.

" πŸ˜€ " . length ; // 2 (two UTF-16 code units, a surrogate pair) [... " πŸ˜€ " ].…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.