String.prototype.isWellFormed() returns true if the string has no lone UTF-16 surrogates, and false if any unpaired half is present. To fix broken text, use toWellFormed().
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call string.isWellFormed. Start with this line.
JavaScript
str.isWellFormed()
Call
What it does
str.isWellFormed()
Primary signature.
string.isWellFormed(...)
Call with the arguments your case needs.
Built into JavaScript. Call isWellFormed(...) on a string (or String instance) — no import required.
Library declarations
JavaScript
str.isWellFormed()
Parameters
This member has no parameters beyond those shown in the signature.
Return Value
Return Value
Description
*
true or false
JavaScript Examples
Example 1 — Basic isWellFormed() Checks
Normal text and a valid emoji pair pass; a lone surrogate fails.
Repair.toWellFormed() returns a new string with U+FFFD (�).
Verify. The repaired string passes isWellFormed().
Encode safely.encodeURI accepts well-formed UTF-16 and no longer throws.
Compatibility
Browser & Runtime Support
String.prototype.isWellFormed() is part of ES2024. It reached Baseline Widely available around October 2023.
✓ Baseline · ES2024
String.prototype.isWellFormed()
Supported in Chrome 111+, Firefox 119+, Safari 16.4+, Edge 111+, and Node.js 20+. Not available in Internet Explorer.
92%Modern browser support
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
String.isWellFormed()Excellent
Bottom line: Safe for modern web apps and current Node LTS (20+). For older targets, feature-detect with if ("isWellFormed" in String.prototype) and polyfill or fall back to a manual surrogate scan.
Frequently Asked Questions
isWellFormed() returns true if the string has no lone UTF-16 surrogates, and false if it contains any unpaired high or low surrogate.
UTF-16 uses pairs of code units for characters above U+FFFF (like many emoji). A lone surrogate is one half of that pair without its matching partner — for example "\uD800" alone.
No. Call it with empty parentheses: str.isWellFormed(). There is nothing to configure.
Before APIs that reject ill-formed strings (such as encodeURI()), when validating text from binary or network sources, or when you want to treat broken surrogate data differently from normal text.
isWellFormed() only checks and returns a boolean. toWellFormed() returns a new string where lone surrogates are replaced with the Unicode replacement character (U+FFFD).
No. Strings are immutable. isWellFormed() only reads and returns true or false.