Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: explain edge case when assigning port to url #19645

Closed
wants to merge 9 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion doc/api/url.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,21 @@ myURL.port = 1234.5678;
console.log(myURL.port);
// Prints 1234

// Out-of-range numbers are ignored
// Numbers which are represented in scientific notation in a String,
// or as very large / small numbers in a Number,
// will be assigned the first digit of the coefficient,
// assuming the number is normalized (for example, 0.9e30 => 9e29).

myURL.port = 4.567e21;
console.log(myURL.port);
// Prints 4 (because the coefficient is 4.567)

// Out-of-range numbers, which are not represented in scientific noation,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: noation -> notation

// will be ignored.
myURL.port = 1e10;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it isn't super clear that (1e10).toString() is '10000000000' -- might be good to clarify that.

It got me thinking that it might be good to just describe the actual algorithm for assigning a number to port in the prose (ll. 322-329): the number is first stringified using String(num), and then the leading characters of the resulting string that are digits are then converted back to a number. (Note: in cases where the default representation of the number is an exponential, the parts after the decimal point or the e character are discarded.) Only then is the range checked.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've rephrased the whole thing, adopting most of your advice, and it is much clearer now in my opinion.

console.log(myURL.port);
// Prints 1234

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this empty line seems redundant.

```

The port value may be set as either a number or as a String containing a number
Expand Down