| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 866965e commit 9142935
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -305,6 +305,31 @@ to percent-encode may vary somewhat from what the [`url.parse()`][] and | |||
| 305 | 305 | ||
| 306 | 306 | Gets and sets the port portion of the URL. | |
| 307 | 307 | ||
| 308 | + The port value may be a number or a string containing a number in the range | ||
| 309 | + `0` to `65535` (inclusive). Setting the value to the default port of the | ||
| 310 | + `URL` objects given `protocol` will result in the `port` value becoming | ||
| 311 | + the empty string (`''`). | ||
| 312 | + | ||
| 313 | + The port value can be an empty string in which case the port depends on | ||
| 314 | + the protocol/scheme: | ||
| 315 | + | ||
| 316 | + | protocol | port | | ||
| 317 | + | :------- | :--- | | ||
| 318 | + | "ftp" | 21 | | ||
| 319 | + | "file" | | | ||
| 320 | + | "gopher" | 70 | | ||
| 321 | + | "http" | 80 | | ||
| 322 | + | "https" | 443 | | ||
| 323 | + | "ws" | 80 | | ||
| 324 | + | "wss" | 443 | | ||
| 325 | + | ||
| 326 | + Upon assigning a value to the port, the value will first be converted to a | ||
| 327 | + string using `.toString()`. | ||
| 328 | + | ||
| 329 | + If that string is invalid but it begins with a number, the leading number is | ||
| 330 | + assigned to `port`. | ||
| 331 | + If the number lies outside the range denoted above, it is ignored. | ||
| 332 | + | ||
| 308 | 333 | ```js | |
| 309 | 334 | const myURL = new URL('https://example.org:8888'); | |
| 310 | 335 | console.log(myURL.port); | |
@@ -346,19 +371,6 @@ console.log(myURL.port); | |||
| 346 | 371 | // Prints 1234 | |
| 347 | 372 | ``` | |
| 348 | 373 | ||
| 349 | - The port value may be set as either a number or as a string containing a number | ||
| 350 | - in the range `0` to `65535` (inclusive). Setting the value to the default port | ||
| 351 | - of the `URL` objects given `protocol` will result in the `port` value becoming | ||
| 352 | - the empty string (`''`). | ||
| 353 | - | ||
| 354 | - Upon assigning a value to the port, the value will first be converted to a | ||
| 355 | - string using `.toString()`. | ||
| 356 | - | ||
| 357 | - If that string is invalid but it begins with a number, the leading number is | ||
| 358 | - assigned to `port`. | ||
| 359 | - Otherwise, or if the number lies outside the range denoted above, | ||
| 360 | - it is ignored. | ||
| 361 | - | ||
| 362 | 374 | Note that numbers which contain a decimal point, | |
| 363 | 375 | such as floating-point numbers or numbers in scientific notation, | |
| 364 | 376 | are not an exception to this rule. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments