本篇仅对隐式转换中的知识点做记录,不深入展开介绍.
注意: PreferredType默认为Number,当input为Date类型数据时,PreferredType为String
- valueOf()
var num = new Number('123'); |
2.toString()
var num = new Number('123sd'); |
type(x) | type(y) | result(x==y) |
---|---|---|
null | undefined | true |
String | Number | Number(x)==y |
Boolean | any | Number(x)==y |
Object | String or Number | toPrimitive(x)==y |
NaN | any | false |
[]==0; //true |
[]=="0" //false |
type(x) | type(y) | result(x+y) |
---|---|---|
String | any | x+toString(y) |
Object | any | toString(x)+toString(y) |
Boolean | Number or Boolean | Number(x)+Number(y) |
"1ac"+true // "1actrue" |