transformation

String.prototype.normalize

Returns the Unicode Normalization Form of the string ('NFC', 'NFD', 'NFKC', or 'NFKD'; default 'NFC'). Essential for reliable comparison of characters that can be represented in multiple code point sequences.

str.normalize([form])

Parameters

Parameter Purpose
form 'NFC' (default), 'NFD', 'NFKC', or 'NFKD'
returns New normalized string; RangeError on invalid form

Examples

const a = '\u00F1';           // 'ñ' (single NFC codepoint)
const b = 'n\u0303';          // 'ñ' (n + combining tilde, NFD)
console.log(a === b);          // false — different code points
console.log(a.normalize() === b.normalize()); // true — both NFC after normalize()

The two literals render identically but are different code point sequences. normalize() (defaulting to NFC) reconciles them.

console.log('ñ'.normalize('NFD') === 'ñ'.normalize('NFD'));

Prints true

console.log('ñ'.normalize('NFD').length);

Prints 2

console.log('①'.normalize('NFKC'));

Prints '1'

Gotcha

An invalid form argument throws a RangeError. NFKC/NFKD apply compatibility mappings and can drastically alter characters — use NFC for most comparison work.

Related methods

← All JS string methods · JS array methods