Skip to content
All references

Encoding reference

Unicode Text

Distinguish bytes, code units, code points and visible graphemes when counting or encoding international text.

8 of 8 entries

Counting

Code point

A → U+0041
😀 → U+1F600

A numbered Unicode value; a visible symbol can contain several code points.

Counting

UTF-16 code units

'😀'.length === 2

JavaScript string length counts UTF-16 code units, not user-perceived characters.

Counting

Code-point iteration

Array.from('😀').length === 1

String iteration groups surrogate pairs but does not combine multi-code-point graphemes.

Counting

Grapheme cluster

e + U+0301 → é

A combining accent can join a letter into one user-perceived text unit.

Encoding

UTF-8 bytes

é → C3 A9
😀 → F0 9F 98 80

UTF-8 encodes a Unicode scalar value using one to four bytes.

Normalization

Canonical normalization

'é'.normalize('NFC') === 'é'

NFC composes canonical equivalents where possible; it does not remove accents.

Normalization

Compatibility normalization

'①'.normalize('NFKC') === '1'

NFKC folds compatibility distinctions; apply it only when losing those distinctions is acceptable.

Encoding

Base64 and Unicode

Text → UTF-8 bytes → Base64

Base64 represents bytes. Agree on a text encoding when decoding them back to text.