Basics
Unicode & UTF-8
The variable-width standard for global text representation.
Time Complexity
O(1)
Space Complexity
O(1-4 bytes)
Interactive Visualization
Technical Guide
UTF-8 is the dominant encoding standard today. It solved the problem of global character support while remaining space-efficient. It uses 1 to 4 bytes per character. ASCII characters take 1 byte, while complex symbols like Emojis take 4. This 'variable-width' nature makes it memory efficient for English but requires careful processing for indexing.
Logical Phases
- 1Checking the first bits of a byte to determine the sequence length.
- 21-byte sequence starts with '0' (ASCII).
- 3Multi-byte sequences use 'leading bits' (110, 1110, 11110) to signal total bytes.
- 4Characters are decoded by combining bits across the sequence.
Implementation
const buf = Buffer.from('🌍');
console.log(buf.length); // 4 bytesExpert Pitfalls
Confusing string.length (code units) with the actual number of bytes in UTF-8.