Handle Unicode text, emoji, encoding, normalization, code points, and safe storage.
Lessons
Avoid the pitfalls developers hit most often.
Common Encoding Mistakes is easiest to learn by reading the example, changing it, and observing the result.
// Encoding survival checklist:
// 1. Save every file as UTF-8 (without BOM)
// 2. <meta charset="UTF-8"> in the first line of <head>
// 3. Send Content-Type: ...; charset=utf-8
// 4. Use utf8mb4 in MySQL (not "utf8")
// 5. Count graphemes for emoji, not .length
// 6. normalize('NFC') before comparing user text
const visibleLength = str =>
[...new Intl.Segmenter().segment(str)].length;
console.log(visibleLength('👍🏽')); // 1Practice the Common Encoding Mistakes example in a small scratch file, then explain what changed and why.