[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/String/isWellFormed [Back]  [Original]

String.prototype.isWellFormed() - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

String.prototype.isWellFormed()

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2023 10.

String isWellFormed() .

In this article

js
isWellFormed()

.

true false .

JavaScript UTF-16 . UTF-16 , UTF-16 , .

isWellFormed() (, ) . isWellFormed() . toWellFormed() . isWellFormed() .

isWellFormed()

js
const strings = [
  // Lone leading surrogate
  "ab\uD800",
  "ab\uD800c",
  // Lone trailing surrogate
  "\uDFFFab",
  "c\uDFFFab",
  // Well-formed
  "abc",
  "ab\uD83D\uDE04c",
];

for (const str of strings) {
  console.log(str.isWellFormed());
}
// Logs:
// false
// false
// false
// false
// true
// true

encodeURI()

encodeURI . encodeURI() isWellFormed() .

js
const illFormed = "https://example.com/search?q=\uD800";

try {
  encodeURI(illFormed);
} catch (e) {
  console.log(e); // URIError: URI malformed
}

if (illFormed.isWellFormed()) {
  console.log(encodeURI(illFormed));
} else {
  console.warn("Ill-formed strings encountered."); // Ill-formed strings encountered.
}

Specification
ECMAScript 2027 LanguageSpecification
# sec-string.prototype.iswellformed


Web Proxy Viewer  |  New URL  |  Original Page