URL: port property
The port property is the port of the address, as a string.
Value
A string.
- Readable and writable.
- Reads back as an empty string when the port is the protocol's default port. Protocols with default ports:
http80,https443,ws80,wss443,ftp21. - Also an empty string when the address has no port.
- Writing an empty string removes the port. A number written is converted to a string first.
- Example: the
portofhttps://u:p@a.com:8080/p/q?x=1#fis8080.
Invalid values
After assignment the whole address is parsed again. When the new value makes the address invalid, the assignment has no effect, the address stays as it was, and nothing is thrown.
Examples
js
const u = new URL('https://a.com:443/');
console.log(JSON.stringify(u.port));
u.port = '8443';
console.log(u.host);Result: Logs "", then a.com:8443. The second line is not verified in the simulator.
Differences from the web
Same as the web.
See also
host: host plus port