Unicode Support in JavaScript, Python, and Other Languages
Every major programming language claims Unicode support, but the implementation details vary significantly. The choice of internal string representation affects how you count characters, split strings, sort text, and handle emoji. Here's a practical guide to what each language actually does.
JavaScript (V8 / SpiderMonkey)
JavaScript strings are sequences of UTF-16 code units. This means "🔥".length === 2—the fire emoji U+1F525 is encoded as a surrogate pair. Use Array.from(str), the spread operator [...str], or str.codePointAt(0) for codepoint-aware operations. Regex with the /u flag treats the string as codepoints: /^.$/u.test("🔥") === true. The Intl.Segmenter API (ES2022) provides grapheme-cluster-aware segmentation—the right tool for emoji-aware string splitting.
Python 3
Python 3 strings are sequences of Unicode code points. len("🔥") === 1 and iteration over the string yields individual code points. This is more intuitive than JavaScript but still wrong for grapheme clusters—a string like "é" encoded as e + combining accent is two code points but one grapheme. Use the grapheme library or unicodedata for precise grapheme-cluster operations. Python's unicodedata module provides access to character properties including name, category, bidirectional class, and normalisation.
Java and Kotlin
Like JavaScript, Java strings are UTF-16 sequences. "🔥".length() === 2. Java provides String.codePointAt() and String.codePoints() for codepoint-aware access, and java.text.BreakIterator for grapheme cluster segmentation. Kotlin inherits Java's string model but adds extension functions like String.codePoints() for convenience.
Go and Rust
Go strings are byte slices of valid (or invalid) UTF-8. A for range loop iterates over runes (code points); len(s) gives byte count. Rust's String is always valid UTF-8; .chars() iterates code points; the unicode-segmentation crate provides grapheme cluster iteration. Both languages make the right trade-offs explicit—you always know whether you're working with bytes, codepoints, or graphemes.
For testing how a specific character behaves, look it up on CharLookup to see its UTF-8 bytes, UTF-16 code units, and properties at a glance.