doc,url: fix url.hostname example

PR-URL: https://github.com/nodejs/node/pull/33735
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
Rishabh Mehan 2020-06-05 01:23:22 -07:00 committed by Antoine du Hamel
parent d05c271f17
commit 665da27e7e

View File

@ -210,9 +210,15 @@ const myURL = new URL('https://example.org:81/foo');
console.log(myURL.hostname);
// Prints example.org
// Setting the hostname does not change the port
myURL.hostname = 'example.com:82';
console.log(myURL.href);
// Prints https://example.com:81/foo
// Use, myURL.host to change the hostname and port
myURL.host = 'example.org:82';
console.log(myURL.href);
// Prints https://example.org:82/foo
```
Invalid host name values assigned to the `hostname` property are ignored.