JS Built-ins
StringString.fromCodePointintermediate

String.fromCodePoint() β€” string length with emoji

πŸ“– Usage Example
String.fromCodePoint(65)       // β†’ 'A'
String.fromCodePoint(9731)     // β†’ 'β˜ƒ'
String.fromCodePoint(128512)   // β†’ 'πŸ˜€'

Use String.fromCodePoint() to create a string from Unicode code point values, including characters outside the BMP.

String.fromCodePoint() β€” Length of Supplementary Characters

A supplementary character (code point > U+FFFF) counts as 2 in .length because JavaScript strings are UTF-16 and the character uses a surrogate pair.

Challenge: Implement emojiLength(cp) that returns the .length of the string produced by String.fromCodePoint(cp).

emojiLength(65)     // β†’ 1
emojiLength(128512) // β†’ 2
πŸ’‘ Hints (1)
  • β€’ JavaScript `.length` counts UTF-16 code units, not code points.