🔰code unit
🚧 under construction
JS ⟩ value ⟩ primitive ⟩ String ⟩ Unicode ⟩ encoding ⟩ UTF-16 ⟩ code unit
UTF-16 code units are 16-bit unsigned integers. (0x0000 ~ 0xFFFF)
string.codePointAt(index)
string.slice(start, end)
string[index]
uses index of code units, not characters❗
.split("") will split by UTF-16 code units and will separate surrogate pairs❗
By default, regular expressions work on code units, not actual characters❗
(dangerous) use code units
string.length
string[index]
string.charCodeAt(index)
(safe) use code points
string iteration (for-of loop)
replit ⟩ code unit
// codeLast updated
Was this helpful?