Example 1 — Positive Indexes
Read UTF-16 code units for "A", "B", and "C".
const text = "ABC";
console.log(text.charCodeAt(0)); // 65
console.log(text.charCodeAt(1)); // 66
console.log(text.charCodeAt(2)); // 67 How It Works
- Build the string.
"ABC"has indexes0,1, and2. - Read each code unit.
"A"→65,"B"→66,"C"→67(ASCII / Unicode). - One unit per index. Each BMP character fits in a single UTF-16 code unit.
- No side effects. The string is unchanged;
charCodeAtonly reads.

