String.prototype.charCodeAt()

Returns the UTF-16 code unit value at the given index.

Since ES1 Spec ↗

Syntax

str.charCodeAt(index)

Parameters

NameTypeRequiredDescription
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

EnvironmentSince version
chrome 1.0
firefox 1.0
safari 1.0
edge 12
node 0.10

See also