If you are building a text input that restricts users to a specific character limit (like a tweet, an SMS gateway, or an SEO meta tag), your first instinct is probably to use String.prototype.length.
If you are doing this in production today, your character counts are fundamentally broken.
Take a look at this standard JavaScript behavior:
javascript
const family = "๐จโ๐ฉโ๐งโ๐ฆ";
console.log(family.length); // Output: 11
const word = "cafรฉ"; // Formatted with a combining acute accent
console.log(word.length); // Output: 5
Top comments (0)