Merge pull request #3113 from leviding/patch-2

feat: improve type conversion for string with whitespace
This commit is contained in:
Ilya Kantor 2022-08-14 11:26:20 +03:00 committed by GitHub
commit caaa05baeb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -70,7 +70,7 @@ Numeric conversion rules:
|`undefined`|`NaN`| |`undefined`|`NaN`|
|`null`|`0`| |`null`|`0`|
|<code>true&nbsp;and&nbsp;false</code> | `1` and `0` | |<code>true&nbsp;and&nbsp;false</code> | `1` and `0` |
| `string` | Whitespaces from the start and end are removed. If the remaining string is empty, the result is `0`. Otherwise, the number is "read" from the string. An error gives `NaN`. | | `string` | Whitespaces (includes spaces, tabs `\t`, newlines `\n` etc.) from the start and end are removed. If the remaining string is empty, the result is `0`. Otherwise, the number is "read" from the string. An error gives `NaN`. |
Examples: Examples:
@ -130,7 +130,7 @@ The conversion follows the rules:
|`undefined`|`NaN`| |`undefined`|`NaN`|
|`null`|`0`| |`null`|`0`|
|<code>true&nbsp;/&nbsp;false</code> | `1 / 0` | |<code>true&nbsp;/&nbsp;false</code> | `1 / 0` |
| `string` | The string is read "as is", whitespaces from both sides are ignored. An empty string becomes `0`. An error gives `NaN`. | | `string` | The string is read "as is", whitespaces (includes spaces, tabs `\t`, newlines `\n` etc.) from both sides are ignored. An empty string becomes `0`. An error gives `NaN`. |
**`Boolean Conversion`** -- Occurs in logical operations. Can be performed with `Boolean(value)`. **`Boolean Conversion`** -- Occurs in logical operations. Can be performed with `Boolean(value)`.