freecoding.school100% FREE · NO SIGNUP
Await StationISSUE #23 of 26

location · hash · search · hostname

PromissaVSRace Condition Rex
Promissa saysThe location object reads and changes the current URL and its parts.

location.href is the full URL; pathname, search (query string), hash, hostname, and protocol break it down. Assigning location.href = url (or location.assign) navigates; location.reload() refreshes; location.replace navigates without a history entry. Parse queries with new URLSearchParams(location.search).

Power-ups you unlock

Race Condition Rex attacks — common mistakes

Boss battleRead a query parameter with URLSearchParams and display it.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre id="o"></pre>
<script>const params=new URLSearchParams('?id=42&tab=info');
document.getElementById('o').textContent='id='+params.get('id')+' tab='+params.get('tab');</script></body></html>
▶ Open the interactive comic issue
‹ History Api · PushState · ReplaceStateNavigator · Ua · Clipboard · Share ›