Skip to content

Commit

Permalink
doc: explain edge case when assigning port to url
Browse files Browse the repository at this point in the history
numbers which are coerced to scientific notation via .toString(),
will behave unexpectedly when assigned to a url's port.

Fixes: nodejs#19595
  • Loading branch information
nodeav authored and LosBunkos committed Mar 27, 2018
1 parent df62e69 commit d719151
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions doc/api/url.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d719151

Please sign in to comment.