CKTIS / JavaScript
String.prototype.codePointAt — reading a code point
The codePointAt(pos) method returns the numeric value of the code point starting at a specified UTF-16 index. It recognizes surrogate pairs, but the index still identifies a code unit, not the next character visible on screen.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
string.codePointAt(pos)String.prototype.codePointAt reads a code point at the zero-based index pos. It returns a Number in the range 0–0x10FFFF, or undefined if the index is outside the string. It does not modify the string.
Indices and length refer to UTF-16 code units. If a valid surrogate pair starts at the index, the method combines its two units into one code point. Otherwise, it returns the value of a single unit, including an isolated surrogate. Calling it on the second element of a pair returns the trailing surrogate's value; it does not move back to the pair's start. By contrast, charCodeAt always reads one unit and returns NaN outside the string.
The method converts pos using ToIntegerOrInfinity before checking bounds: an omitted argument or NaN means 0, and fractional parts are truncated toward zero. A resulting index that is negative, infinite, or not less than length produces undefined. For an empty string, every successfully converted index is out of bounds. If conversion throws, the exception propagates even for an empty string: for example, "".codePointAt(0n) throws a TypeError.
Do not treat incrementing the index by one as stepping through code points: this can enter the middle of a pair. A code point also need not represent an entire character visible on screen. This is an ECMAScript method, not a browser API; the standard alone does not establish support in a particular browser.
Examples
const text = "A\u{1F600}B";
console.log(text.length);
console.log(text.codePointAt(1));
console.log(text.charCodeAt(1));
console.log(text.codePointAt(2));
console.log(text.codePointAt(4));Result
4 128512 55357 56832 undefined
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.