String.charCodeAt() Character code at an index
Last updated: 2026-09-09
String.charCodeAt() Character code at an index
charCodeAt returns the UTF-16 code unit at the given index.
| Category | Strings |
|---|---|
| ES version | ES1 |
📝 Syntax
const code = str.charCodeAt(index);
⚙️ Parameters
| index | Character position, default 0. |
|---|
Returns:A UTF-16 code unit (0~65535).
Mutates the original:No (returns a new value)
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
65
NaN
💡 Tip Use codePointAt for full Unicode code points.
ℹ️ info String.fromCharCode(65) converts back to A.
🌐 Browser support
| Browser | |||||
|---|---|---|---|---|---|
| String.charCodeAt() | ✓ v1 | ✓ v12 | ✓ v1 | ✓ v1 | ✓ v1 |
| Supported by all modern browsers | |||||
🏷️ Related Items
💡 Related Cases
More case studies coming soon — check back later.
📚 Related Tutorials
❓ FAQ
QcharCodeAt vs codePointAt?
AcharCodeAt gives UTF-16 code units; codePointAt gives full code points.
QWhat about out-of-range?
AReturns NaN, not an error or empty string.
QHow to iterate each character?
AUse for...of or [...str] — they handle surrogate pairs correctly.