Handle Unicode text, emoji, encoding, normalization, code points, and safe storage.
Lessons
Measure emoji length without splitting them.
Counting Emoji Correctly is easiest to learn by reading the example, changing it, and observing the result.
const text = 'Hi👋🏽 family👨👩👧👦!';
// Wrong: counts UTF-16 code units, splits emoji
console.log(text.length);
// Right: count what the user perceives as characters
const seg = new Intl.Segmenter('en', { granularity: 'grapheme' });
const graphemes = [...seg.segment(text)].map(s => s.segment);
console.log(graphemes.length, graphemes);Practice the Counting Emoji Correctly example in a small scratch file, then explain what changed and why.