JS Built-ins
← URL13 / 20
URLbeginner

URL#toJSON() β€” returns a string

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

Setting properties like pathname updates the URL in-place.

URL#toJSON()

url.toJSON() returns the serialized URL as a string (same as href).

Challenge: Verify the return type of toJSON().

πŸ’‘ Hints (1)
  • β€’ toJSON is used when JSON.stringify serializes a URL object