en.javascript.info
en.javascript.info copied to clipboard
UTF-16 vs UTF-32 misconception
https://javascript.info/string
A unicode symbol with the given UTF-32 encoding. Some rare characters are encoded with two unicode symbols, taking 4 bytes. This way we can insert long codes
UTF 32 characters always take 4 bytes (4 bytes = 32 bits hence the name).
UTF 16 characters usually take 2 bytes (16 bits), but some characters may be composed of two code units, taking 4 bytes. BTW, such compound characters are not that rare if you are dealing with CJK languages.
alert('\uD834\uDF06'); // Two utf 16 code units make single character 𝌆
alert('𝌆'.length); // 2
alert('a'.length); // 1, different characters have different length
What's the issue exactly?