.codePointAt()

Anonymous contributor's avatar
Anonymous contributor
Published Jun 20, 2025
Contribute to Docs

The .codePointAt() method is a JavaScript string method that returns a non-negative integer representing the Unicode code point of the character at a specified index. Unlike the older .charCodeAt() method, .codePointAt() accurately handles the full range of Unicode characters, including emojis, symbols, and characters from any language.

Syntax

string.codePointAt(index);

Parameters:

  • index: A non-negative integer representing the position in the string to get the code point from. If the index is out of range, it returns undefined.

Return value:

  • A non-negative integer representing the Unicode code point at the specified index.
  • undefined if no character exists at that index.

Example

The following example demonstrates how .codePointAt() retrieves Unicode values from strings, including regular characters, emojis, compound emojis, and out-of-range positions:

const text = 'Hello 😀';
// Accessing the second character in the string.
console.log(text.codePointAt(1));
// Accessing the emoji
console.log(text.codePointAt(6));
// Accessing a character at a position that is beyond the string length.
console.log(text.codePointAt(12));
// Compare with a multi-byte character
const emoji = '👨‍💻'; // Man technologist emoji (compound emoji)
console.log(emoji.codePointAt(0));
console.log(emoji.codePointAt(2));

The output of this code is:

101
128512
undefined
128104
8205

Codebyte Example

The example retrieves Unicode code points from a string containing text and emojis, handling multi-byte characters and out-of-range positions correctly:

Code
Output
Loading...

All contributors

Contribute to Docs

Learn JavaScript on Codecademy