JavaScript Location Get Hostname

In this section, we will learn what the location host property is and how to use it in JavaScript.

JavaScript Location host Property

With the help of the `host` property, we can get or set the host name and the port number of the currently loaded document.

Note: if the port number is not specified, the return value will be just the host name alone.

Location host Property Syntax: = “new location”;

Example: document location hostname

const value =;



Leave a Reply