UTF-16
What is UTF-16?
UTF-16 encodes Unicode code points using 2-byte (16-bit) code units. Characters in the Basic Multilingual Plane (U+0000 to U+FFFF) use one code unit. Characters above U+FFFF (emoji, rare CJK, historic scripts) use a surrogate pair: two code units totaling 4 bytes.
UTF-16 is the internal string encoding for JavaScript, Java, C#, and Windows APIs. This matters when you index into strings:
UTF-16 is the internal string encoding for JavaScript, Java, C#, and Windows APIs. This matters when you index into strings:
"face".length in JavaScript returns 2 (two code units for one emoji), not 1. Surrogate handling is the #1 source of Unicode bugs in these languages. For file storage and network transfer, UTF-8 is almost always better - it is more compact for Latin text and has no byte-order ambiguity. UTF-16 requires a BOM (Byte Order Mark) or explicit endianness specification.