window.location is a Location object that splits the current address into the same parts as a URL, including protocol, hostname and port. The listing ran at https://shop.example.com:8080/cart/view.html?id=42#total.
for (const key of ['origin', 'host', 'pathname', 'search', 'hash']) {
console.log(key.padEnd(9), location[key]);
}Output
origin https://shop.example.com:8080 host shop.example.com:8080 pathname /cart/view.html search ?id=42 hash #total
Writing to location navigates. location.href = url and assign(url) add a history entry; replace(url) overwrites the current one, so Back skips it. Setting hash only scrolls and fires hashchange; setting search or pathname loads a new page. reload() takes no standard arguments (the reload(true) cache bypass works only in Firefox 555 ). Parse query strings with URLSearchParams (URLSearchParams).