JS Built-ins
← String168 / 195
StringString.prototype.toWellFormedintermediate

String.prototype.toWellFormed() β€” string with emoji unchanged

πŸ“– Usage Example
'hello'.toWellFormed()      // β†’ 'hello'
'πŸ˜€'.toWellFormed()         // β†’ 'πŸ˜€'
'οΏ½'.toWellFormed()     // β†’ 'οΏ½'

Use toWellFormed() to replace lone surrogate code units with the Unicode replacement character U+FFFD (ES2024).

String.prototype.toWellFormed() β€” Emoji

Emoji characters use surrogate pairs correctly. A well-formed emoji string is returned unchanged.

Challenge: Implement wellFormedEmoji() that shows an emoji string is unchanged.

wellFormedEmoji() // β†’ 'πŸ˜€'
πŸ’‘ Hints (1)
  • β€’ Emoji like πŸ˜€ use a valid high–low surrogate pair, so `toWellFormed()` leaves them unchanged.