Skip to content

Commit ad7cd2b

Browse files
authored
Update number.md (wangdoc#247)
parseFloat参数不是字符串会先进行隐式类型转换
1 parent 37de2eb commit ad7cd2b

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

docs/types/number.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,15 @@ parseFloat('3.14more non-digit characters') // 3.14
552552
parseFloat('\t\v\r12.34\n ') // 12.34
553553
```
554554

555-
如果参数不是字符串,或者字符串的第一个字符不能转化为浮点数,则返回`NaN`
555+
如果参数不是字符串,则会先转为字符串再转换。
556+
557+
```javascript
558+
parseFloat([1.23]) // 1.23
559+
// 等同于
560+
parseFloat(String([1.23])) // 1.23
561+
```
562+
563+
如果字符串的第一个字符不能转化为浮点数,则返回`NaN`
556564

557565
```javascript
558566
parseFloat([]) // NaN

0 commit comments

Comments
 (0)