Last updated: August 29, 2026.
JavaScript strings use UTF-16 code units. Indexing can return half of a surrogate pair, so use codePointAt and iterate by Unicode characters.
Read one code point
Convert the numeric result to uppercase hexadecimal for U+ notation.
function unicodeLabel(character) {
const point = character.codePointAt(0);
if (point === undefined) throw new Error('A character is required.');
return 'U+' + point.toString(16).toUpperCase().padStart(4, '0');
}
console.log(unicodeLabel('A'));
console.log(unicodeLabel('\u{1F600}'));Inspect a complete string
A for-of loop advances by code point, keeping supplementary characters intact.
function listCodePoints(text) {
return Array.from(text, character => ({
character,
codePoint: 'U+' + character.codePointAt(0).toString(16).toUpperCase()
}));
}
console.table(listCodePoints('A\u0301'));Code points are not visible characters
Combining marks and joined emoji can contain several code points while appearing as one grapheme. Use Intl.Segmenter for cursor movement, truncation, or counting user-perceived characters.
Handle full Unicode characters
JavaScript strings use UTF-16 code units, so indexing a string can split a character represented by a surrogate pair. Iterate with for…of or Array.from when the task is about Unicode characters rather than individual code units.
Test a basic Latin letter, an accented character, and an emoji. Confirm both the hexadecimal code point and the number of JavaScript code units so the distinction is visible.
- Use codePointAt rather than charCodeAt for full code points.
- Format hexadecimal values consistently.
- Do not assume one visible glyph equals one code point.
Keep the byte encoding, declaration, storage, and decoder consistent. When diagnosing a problem, preserve the original input and change one boundary at a time so the actual cause remains visible.
Continue with HTML entities, special characters, and encoding comparison.
Reference: MDN String.codePointAt reference.