prefer-code-point

March 27, 2026 ยท View on GitHub

๐Ÿ“ Prefer String#codePointAt(โ€ฆ) over String#charCodeAt(โ€ฆ) and String.fromCodePoint(โ€ฆ) over String.fromCharCode(โ€ฆ).

๐Ÿ’ผ This rule is enabled in the following configs: โœ… recommended, โ˜‘๏ธ unopinionated.

๐Ÿ’ก This rule is manually fixable by editor suggestions.

Unicode is better supported in String#codePointAt() and String.fromCodePoint().

Examples

// โŒ
const unicorn = '๐Ÿฆ„'.charCodeAt(0).toString(16);

// โœ…
const unicorn = '๐Ÿฆ„'.codePointAt(0).toString(16);
// โŒ
const unicorn = String.fromCharCode(0x1f984);

// โœ…
const unicorn = String.fromCodePoint(0x1f984);