Skip to content

Files

Latest commit

 

History

History
21 lines (15 loc) · 543 Bytes

prefer-code-point.md

File metadata and controls

21 lines (15 loc) · 543 Bytes

Pattern: Character code manipulation without Unicode support

Issue: -

Description

The String#codePointAt() and String.fromCodePoint() methods provide better Unicode support compared to their older counterparts charCodeAt() and fromCharCode(), especially for characters outside the BMP (Basic Multilingual Plane).

Examples

Example of incorrect code:

"🦄".charCodeAt(0);
String.fromCharCode(0x1f984);

Example of correct code:

"🦄".codePointAt(0);
String.fromCodePoint(0x1f984);