URL: port property

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

Value

A string.

Examples

js

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

Specifications

Specification
URL Standard
# dom-url-port

Browser compatibility

BCD tables only load in the browser

See also

  • The URL interface it belongs to.