JS Built-ins
← String169 / 195
StringString.prototype.toWellFormedbeginner

String.prototype.toWellFormed() β€” empty string

πŸ“– 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() β€” Empty String

Calling toWellFormed() on an empty string returns an empty string.

Challenge: Implement wellFormedEmpty() that calls toWellFormed on an empty string.

wellFormedEmpty() // β†’ ''
πŸ’‘ Hints (1)
  • β€’ `"".toWellFormed()` returns `""` since there are no characters to process.