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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

string.charCodeAt(index)

Parameters

ParameterDescription
index optional Position from 0. Default: 0

Return value

A number, or NaN if the index is out of range.

Examples

Character codesTry it yourself
console.log("A".charCodeAt(0), "a".charCodeAt(0), "€".charCodeAt(0));

Output

65 97 8364
Emoji take two code unitsTry it yourself
const smile = "\u{1F600}";
console.log(smile.length, smile.charCodeAt(0), smile.codePointAt(0));

Output

2 55357 128512

Version history

VersionChange
JavaScript ES1Added

In other languages

Was this page helpful?