JS Built-ins
URLbeginner

URL Constructor β€” basic absolute URL

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

URL() parses a URL string into structured components like hostname, pathname, and search.

URL Constructor

new URL(href) parses an absolute URL string into its component parts.

Challenge: Use new URL('https://example.com') and verify the hostname is 'example.com'.

πŸ’‘ Hints (1)
  • β€’ new URL() takes an absolute URL string as its first argument