JS Built-ins
← URL16 / 20
URLbeginner

URL.canParse() β€” valid absolute URL returns true

πŸ“– Usage Example
URL.canParse('https://example.com')  // β†’ true
URL.canParse('not a url')         // β†’ false

URL.canParse() returns true if the string is a valid URL without throwing.

URL.canParse()

URL.canParse(href) returns true if the string is a valid URL, false otherwise.

Challenge: Verify that URL.canParse('https://example.com') returns true.

πŸ’‘ Hints (1)
  • β€’ URL.canParse() is a safe alternative to try/catch around new URL()