Favorites

JavaScript String.prototype.charCodeAt() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
String.prototype.charCodeAt()
JavaScript String Instance methodThis method is supported by all modern browsers.
Updated 28th November 2026

The charCodeAt() method returns the numeric UTF-16 code of the character at a given index.

Description

The charCodeAt() method returns the UTF-16 code unit at the index, a number between 0 and 65535. For characters made of two code units (surrogate pairs), it returns only half of the pair; use codePointAt() to get the full Unicode code point.

Character codes are useful for simple checks and transformations, such as testing whether a character is an ASCII letter (codes 65 to 90 and 97 to 122) or shifting letters in a Caesar cipher. For readability, comparing characters directly, or using a regular expression, is often clearer than working with numbers.

If the index is outside the string, it returns NaN. When you need to know whether a code is one half of a surrogate pair, check whether it's in the range 0xD800 to 0xDFFF; codePointAt() deals with pairs for you.

Syntax

string.charCodeAt(index)

Parameters

  • indexThe position of the character, from 0. Defaults to 0.

Return Value

A number from 0 to 65535 (the UTF-16 code unit), or NaN if the index is out of range.

Example

console.log('A'.charCodeAt(0));
console.log('abc'.charCodeAt(2));
console.log('😀'.charCodeAt(0), '😀'.codePointAt(0));

Browser Support

The following information will show you the current browser support for the String.prototype.charCodeAt() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee