JS Built-ins
URLbeginner

URL Constructor β€” relative URL with base

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

Pass a base URL as the second argument to resolve relative URLs.

URL Constructor β€” relative + base

new URL(relative, base) resolves a relative path against a base URL.

Challenge: Use new URL('/path', 'https://example.com') and check the pathname and href.

πŸ’‘ Hints (1)
  • β€’ The second argument to new URL() is the base URL