Two strings can display as “café” yet fail `===`. The final é can be one code unit, U+00E9, or an e followed by a combining accent, U+0065 U+0301. JavaScript compares the resulting UTF-16 code-unit sequences, not their appearance. Their `length` values can differ too: four code units versus five. section 2.1.2
Compare equivalent spellings
const a = 'caf\u00E9'; const b = 'cafe\u0301'; a === b; // false a.normalize() === b.normalize(); // true Normalize both operands before comparing them. `normalize()` defaults to NFC, which produces the composed form here. section 2.1.2
Table 2.4 Unicode normalization forms
|
Form
|
Name
|
Description
|
Example Input
|
Result
|
Code Units
|
|
NFC
|
Canonical Composition
|
Decomposes then recombines
characters
|
café (e + ́)
|
café
|
U+0063 U+0061 U+0066 U+00E9
|
|
NFD
|
Canonical Decomposition
|
Separates base characters
from combining marks (like accents)
|
café
|
café (e + ́)
|
U+0063 U+0061 U+0066 U+0065
U+0301
|
|
NFKC
|
Compatibility Composition
|
Like NFC but also
normalizes variants
|
fi (ligature, one symbol)
|
fi (two symbols)
|
U+0066 U+0069
|
|
NFKD
|
Compatibility
Decomposition
|
Like NFD but also
normalizes variants
|
½ (one symbol)
|
1⁄2 (three symbols)
|
U+0031 U+2044 U+0032
|
The four forms make different choices. NFC composes canonically equivalent sequences; NFD separates base characters and combining marks. NFKC and NFKD also normalize compatibility variants, such as the fi ligature or ½. Choose a form deliberately, then use it consistently. section 2.1.2
function registerUser (username) {
const normalized = username.normalize();
if (existingUsers.some(u => u.normalize() === normalized)) {
return 'Username already taken';
}
existingUsers.push(username);
return 'Registration successful';
}A username check can miss an existing, visually identical name when their code-unit sequences differ. Normalize the incoming name and each stored name before testing equality. section 2.1.2























