JavaScript normalize(): Canonical Unicode Equivalence
Quick answer
Normalization transforms text to a selected Unicode normalization form. Canonically equivalent sequences may look alike but compare unequal until normalized.
How it works
normalize() defaults to NFC; NFD decomposes canonical equivalents. NFKC and NFKD also apply compatibility mappings, which can discard meaningful distinctions such as typography. Normalize both operands using an explicit policy before comparing. This does not automatically case-fold, remove marks or resolve confusable characters.
const a = "é"; const b = "é";console.log(a === b, a.normalize() === b.normalize());Expected output in Node.js:
false trueCanonical equivalence does not imply identical unit sequences before NFC.
console.log("é".normalize("NFD").length, "①".normalize("NFKC"));Expected output in Node.js:
2 1NFD decomposes the accent; compatibility normalization maps circled one to digit 1.
Common mistakes
Do not normalize credentials or identifiers arbitrarily. Choose a policy that matches the system contract and keep original display text when needed.
Practice
Compare two spellings of an accented label before and after NFC, retaining the original text.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
JavaScript normalize(): Canonical Unicode Equivalence — Knowledge Check
Apply the taught concept and predict the output.
Which normalization form is the default for String.normalize?
Which form may erase compatibility distinctions while composing?
Does normalization alone make uppercase and lowercase Latin letters equal?
What is the exact console output in JavaScript normalize(): Canonical Unicode Equivalence example 1?
const a = "é"; const b = "é";console.log(a === b, a.normalize() === b.normalize());What is the exact console output in JavaScript normalize(): Canonical Unicode Equivalence example 2?
console.log("é".normalize("NFD").length, "①".normalize("NFKC"));