String.prototype.charCodeAt()
Returns the UTF-16 code unit value at the given index.
Syntax
str.charCodeAt(index) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
index | number | No | Zero-based index of the character. Defaults to 0. |
Returns
number — An integer 0 to 65535, or NaN if the index is out of range.
Examples
console.log('ABC'.charCodeAt(0));
Output
65
console.log('abc'.charCodeAt(10));
Output
NaN
Notes
Returns a 16-bit code unit, not a full code point. For characters outside the
BMP (e.g. emoji) use `codePointAt`. Returns NaN for out-of-range indices.
Browser & runtime support
| Environment | Since version |
|---|---|
| chrome | 1.0 |
| firefox | 1.0 |
| safari | 1.0 |
| edge | 12 |
| node | 0.10 |