.codePointAt()
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 returnsundefined
.
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 emojiconsole.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 characterconst emoji = '👨💻'; // Man technologist emoji (compound emoji)console.log(emoji.codePointAt(0));console.log(emoji.codePointAt(2));
The output of this code is:
101128512undefined1281048205
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:
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.