JavaScript Location Get hostname

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

JavaScript Location hostname Property

The `hostname` property is used to set or return the server name of a URL.

Note: the return value is without port number.

Location hostname Property Syntax:

location.hostname;

location.hostname = “address”;

Example: document location hostname

const value = location.hostname;

console.log(value);

Output:

www.enjoytutorials.com/

Leave a Reply