JS Built-ins
← URL14 / 20
URLbeginner

URL#toJSON() β€” equals href

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

Modifying searchParams automatically updates the URL's search string.

URL#toJSON() β€” equals href

url.toJSON() returns the same string as url.href.

Challenge: Confirm toJSON() is equal to href.

πŸ’‘ Hints (1)
  • β€’ Both toJSON() and href return the fully serialized URL