toWellFormed < String < JavaScript
The toWellFormed() of a String returns a string where all lone surrogates of the string are replaced with the Unicode replacement character U+FFFD.
const loneLeadingSurrogate = "ab\uD800".toWellFormed();
console.log(loneLeadingSurrogate);
// "ab�"
const loneLeadingSurrogate1 = "ab\uD800c".toWellFormed();
console.log(loneLeadingSurrogate1);
// "ab�c"
const loneTrailingSurrogate = "\uDFFFab".toWellFormed();
console.log(loneTrailingSurrogate);
// "�ab"
const wellFormed = "ab\uD83D\uDE04c".toWellFormed();
console.log(wellFormed);
// "ab😄c"