JS Built-ins
← URL12 / 20
URLintermediate

URL#toString() β€” reflects property changes

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

toJSON() returns the same string as href, used during JSON.stringify().

URL#toString() β€” after mutation

Changing a URL property (e.g. pathname) updates the serialized URL returned by toString().

Challenge: Change pathname and verify toString() reflects the change.

πŸ’‘ Hints (1)
  • β€’ URL properties are mutable β€” setting them updates the URL