JavaScript (ES2026) reference · String Methods
JavaScript String charCodeAt() Method
Return the UTF-16 code unit (0 to 65535) at an index. For emoji and other astral characters use codePointAt().
JavaScript (ES2026) Since ES1
Syntax
string.charCodeAt(index)
Parameters
| Parameter | Description |
|---|---|
index optional |
Position from 0. Default: 0 |
Return value
A number, or NaN if the index is out of range.
Examples
console.log("A".charCodeAt(0), "a".charCodeAt(0), "€".charCodeAt(0));
Output
65 97 8364
const smile = "\u{1F600}";
console.log(smile.length, smile.charCodeAt(0), smile.codePointAt(0));
Output
2 55357 128512
Version history
| Version | Change |
|---|---|
| JavaScript ES1 | Added |
In other languages
Related
string.codePointAt()· Return the full Unicode code point at an index, correctly handling emoji and other characters outside the BMP.String.fromCharCode()· Create a string from UTF-16 code units, for example String.fromCharCode(72, 105) gives "Hi".- JavaScript Strings · tutorial
- JavaScript String Methods · tutorial