Skip to main content

Character code

The method charCodeAt retrieves the Unicode character code of a single character:

var charCode = "µ".charCodeAt(); // The character code of the letter µ is 181

To get the character code of a character in a string, the 0-based position of the character is passed as a parameter to charCodeAt:

var charCode = "ABCDE".charCodeAt(3); // The character code of "D" is 68

Some Unicode symbols don't fit in a single character, and instead require two UTF-16 surrogate pairs to encode. This is the case of character codes beyond 216 - 1 or 63553. These extended character codes or code point values can be retrieved with codePointAt:

// The Grinning Face Emoji has code point 128512 or 0x1F600
var codePoint = "????".codePointAt();