JS Built-ins
URLintermediate

URL Constructor β€” invalid URL throws TypeError

πŸ“– Usage Example
const u = new URL('https://example.com')
u instanceof URL  // β†’ true

URL instances can be checked with instanceof.

URL Constructor β€” TypeError

Passing an invalid URL string to new URL() throws a TypeError.

Challenge: Verify that new URL('not-a-url') throws a TypeError.

πŸ’‘ Hints (1)
  • β€’ Wrap new URL() in a try/catch to handle the TypeError