-
-
Notifications
You must be signed in to change notification settings - Fork 35k
doc: explain edge case when assigning port to url #19645
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
Changes from 1 commit
d719151
2cc61c1
257eae0
e402ff4
64863ee
aedadce
a55b432
0d39ca6
92919bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -317,6 +317,15 @@ console.log(myURL.port); | |
| myURL.port = 1e10; | ||
| console.log(myURL.port); | ||
| // Prints 1234 | ||
|
|
||
|
||
| // Out-of-range numbers, which are converted to exponential | ||
|
||
| // notation via .toString(), will behave as strings with leading zeroes. | ||
| // This means that the port will be assigned the integer part of the coefficient, | ||
| // assuming the number is normalized (for example, 0.9e10 => 9e9). | ||
| // See https://www.ecma-international.org/ecma-262/6.0/#sec-tostring-applied-to-the-number-type for more information | ||
|
||
| myURL.port = 4.567e21; | ||
| console.log(myURL.port); | ||
| // Prints 4 (because the coefficient is 4.567) | ||
| ``` | ||
|
|
||
| The port value may be set as either a number or as a String containing a number | ||
|
|
||
There was a problem hiding this comment.
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
portin the prose (ll. 322-329): the number is first stringified usingString(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 theecharacter are discarded.) Only then is the range checked.There was a problem hiding this comment.
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.