JavaScript window location hostname property enables you to get the domain name or IP address of the current URL. If the current URL of the web broswer contains domain name then location hostname property returns domain name and if URL contains IP address then hostname property returns IP address of the current URL. JavaScript location hostname property do not the port number of the current URL whether the browser is showing the port number or not. JavaScript location object belongs to JavaScript window object that allows you to access the hostname property using window.location.hostname. You can also access the hostname property directly as location.hostname.
Try the sample below to learn and practice the code functionality of JavaScript window location hostname property: