String.prototype.codePointAt(index) returns the full Unicode code point starting at a UTF-16 index. For many emoji that use a surrogate pair, that number can be larger than 65535. Out of range returns undefined.
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call string.codePointAt. Start with this line.
JavaScript
string.codePointAt(index)
Call
What it does
string.codePointAt(index)
Primary signature.
string.codePointAt(...)
Call with the arguments your case needs.
Built into JavaScript. Call codePointAt(...) on a string (or String instance) — no import required.
Library declarations
JavaScript
string.codePointAt(index)
Parameters
Parameter
Description
index
Required. UTF-16 position (not a code-point count)
undefined check
Optional. Needed when missing indexes matter
Return Value
Return Value
Description
*
Non-negative integer, or undefined
JavaScript Examples
Example 1 — ASCII Code Points
For BMP characters, codePointAt matches the familiar ASCII numbers.
Rule of thumb. Need the whole character number? Prefer codePointAt.
Compatibility
Browser & Runtime Support
String.prototype.codePointAt() is part of ES2015 and is Baseline Widely available in modern browsers and current JavaScript runtimes.
✓ Baseline · ES2015
String.prototype.codePointAt()
Supported in Chrome, Firefox, Safari, Edge, and modern Node.js / Deno / Bun. Not available in Internet Explorer without a polyfill.
95%Modern browser support
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
String.codePointAt()Excellent
Bottom line: Safe for modern web apps and current Node LTS. For IE11 or very old engines, feature-detect with if (typeof String.prototype.codePointAt === "function") and fall back to a small polyfill — or stick with charCodeAt when you only need BMP characters.
Frequently Asked Questions
codePointAt(index) returns a non-negative integer — the Unicode code point starting at that UTF-16 index. Out of range, it returns undefined.
charCodeAt() always returns one UTF-16 code unit (0–65535). codePointAt() returns the full Unicode code point, which can be larger than 65535 for surrogate pairs (many emoji).
undefined. That differs from charCodeAt() (NaN) and charAt() ("").
Indexes are still UTF-16 code units (same as length and charAt). For a two-unit emoji, index at the high surrogate returns the full code point; the next index lands on the trailing surrogate.
Use String.fromCodePoint(codePoint). Prefer that over fromCharCode() when the value may be above 65535.
Prefer for...of or [...str] — they iterate by code point. A plain for (i = 0; i < str.length; i++) loop visits both halves of a surrogate pair.