- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript location Object
JavaScript Storage & BOM
JavaScript location Object
locationdescribes the current URL and can be used to navigate to another page.
Every part of the address is available as its own property.
Assigning to it sends the browser somewhere else.
Example
Example
javascript
console.log(typeof location.href);
console.log(typeof location.hostname);Both are string.
Reading the URL
href is the whole address.
pathname is the part after the domain.
search is the query string, starting with a question mark.
