en.javascript.info icon indicating copy to clipboard operation
en.javascript.info copied to clipboard

UTF-16 vs UTF-32 misconception

Open Romex91 opened this issue 6 years ago • 1 comments

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

Romex91 avatar Jul 30 '20 14:07 Romex91

What's the issue exactly?

iliakan avatar Sep 24 '20 17:09 iliakan