The port property of the URL interface is a string containing the port number of the URL.

Note: If an input string passed to the URL() constructor doesn't contain an explicit port number (e.g., https://localhost) or contains a port number that's the default port number corresponding to the protocol part of the input string (e.g., https://localhost:443), then in the URL object the constructor returns, the value of the port property will be the empty string: ''.

Note: This feature is available in Web Workers


A string.


const url = new URL('https://mydomain.com:80/svn/Repos/');
console.log(url.port); // Logs '80'


URL Standard
# dom-url-port

Browser compatibility

BCD tables only load in the browser

See also

  • The URL interface it belongs to.