JavaScript Curriculum
BOM — Window & Location
mediumThe coffee shop menu needs URL-based filtering — sharing a link to '/menu?category=coffee' should pre-filter the page. The History API lets you update the URL without reloading, keeping the back button working correctly.
BOM — Window & Location
The DOM is the document tree. The BOM (Browser Object Model) is everything else — the window, URL, history, navigator, and screen. window is the global object in the browser — every variable you declare at the top level becomes a property of it.
The Window Object
Explore dimensions, scroll position, navigator info, and the classic dialog methods:
window.innerWidthViewport width including scrollbar
1280// In browser console: console.log(window.innerWidth) // → 1280
location & URLSearchParams
The current URL, broken into pieces — and how to read query parameters cleanly:
location.hrefhttps://thegrind.com/menu?category=coffee&sort=price#featuredlocation.originhttps://thegrind.comlocation.protocolhttps:location.hostthegrind.comlocation.pathname/menulocation.search?category=coffee&sort=pricelocation.hash#featuredconst params = new URLSearchParams(location.search)
params.get('category') // → 'coffee'
params.get('sort') // → 'price'history.pushState()Add to history without reloadhistory.replaceState()Replace current entry, no reloadhistory.back()Go back one stephistory.forward()Go forward one stephistory.go(-2)Go back/forward N stepsHistory API — URL without Reload
Update the URL and manage the back button without page reloads — the foundation of single-page apps:
/{"page":"home"}// History stack ready
Your Challenge
On page load: read new URLSearchParams(location.search).get('category') and filter cards. Wire the category dropdown's change event to call history.pushState({category: val}, '', \?category=${val}`). Listen for window.addEventListener('popstate', e => applyFilter(e.state.category))` so the back button works.
Challenge
Read location.search and use URLSearchParams to get the 'category' query parameter. Apply it as a filter on page load. When the user changes the filter dropdown, use history.pushState to update the URL without a reload.
BOM — Window & Location
mediumThe coffee shop menu needs URL-based filtering — sharing a link to '/menu?category=coffee' should pre-filter the page. The History API lets you update the URL without reloading, keeping the back button working correctly.
BOM — Window & Location
The DOM is the document tree. The BOM (Browser Object Model) is everything else — the window, URL, history, navigator, and screen. window is the global object in the browser — every variable you declare at the top level becomes a property of it.
The Window Object
Explore dimensions, scroll position, navigator info, and the classic dialog methods:
window.innerWidthViewport width including scrollbar
1280// In browser console: console.log(window.innerWidth) // → 1280
location & URLSearchParams
The current URL, broken into pieces — and how to read query parameters cleanly:
location.hrefhttps://thegrind.com/menu?category=coffee&sort=price#featuredlocation.originhttps://thegrind.comlocation.protocolhttps:location.hostthegrind.comlocation.pathname/menulocation.search?category=coffee&sort=pricelocation.hash#featuredconst params = new URLSearchParams(location.search)
params.get('category') // → 'coffee'
params.get('sort') // → 'price'history.pushState()Add to history without reloadhistory.replaceState()Replace current entry, no reloadhistory.back()Go back one stephistory.forward()Go forward one stephistory.go(-2)Go back/forward N stepsHistory API — URL without Reload
Update the URL and manage the back button without page reloads — the foundation of single-page apps:
/{"page":"home"}// History stack ready
Your Challenge
On page load: read new URLSearchParams(location.search).get('category') and filter cards. Wire the category dropdown's change event to call history.pushState({category: val}, '', \?category=${val}`). Listen for window.addEventListener('popstate', e => applyFilter(e.state.category))` so the back button works.
Challenge
Read location.search and use URLSearchParams to get the 'category' query parameter. Apply it as a filter on page load. When the user changes the filter dropdown, use history.pushState to update the URL without a reload.