String

String.prototype.codePointAt

Returns a non-negative integer that is the Unicode code point value at the given position

Syntax

JavaScript
string.codePointAt(pos)

Parameters

ParameterTypeDescription
posnumberPosition of the character

Return Value

A number representing the code point, or undefined if out of range

Examples

Basic Usage
const emoji = '😀';
console.log(emoji.codePointAt(0)); // 128512
Practical Example
console.log('ABC'.codePointAt(0)); // 65
console.log('☃'.codePointAt(0)); // 9731
Advanced Usage
const str = '𝒜';
console.log(str.codePointAt(0)); // 119964
console.log(String.fromCodePoint(119964)); // '𝒜'

Understanding String.prototype.codePointAt

The String.prototype.codePointAt method in JavaScript returns a non-negative integer that is the Unicode code point value at the given position. It belongs to the String object and is one of the most widely used methods for working with string values in modern JavaScript and TypeScript applications.

The method signature is string.codePointAt(pos). It accepts 1 parameter: pos. When called, it returns a number representing the code point, or undefined if out of range. Understanding when and how to use codePointAt() helps you write more expressive, readable code.

Common use cases for String.prototype.codePointAt include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like string-charcodeat, string-fromcodepoint, string-charat, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for String.prototype.codePointAt is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.

Browser Compatibility

Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.

Related Methods

More String Methods

Other methods in the String object

Related Tools

More String Methods

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.