1-1.字符串转number
函数 number();
var str = "12";
console.log(Number(str)) //12
var s = "";
var p = " ";
console.log(Number(s))
console.log(Number(p))
srring转number
parseInt() | 转为int型 |
---|---|
parsefloat() | 转为小数型 |
string-->number
parseInt(); "12px";
parseFloat(); "12.434px";
console.log(Number("12px")) //NaN
1-2 boolean转number
Number(true) //1
Number(false) //0
1-3 number转boolean
tips: 0转换为false,其他都为true
1-4 string转boolean
tips:””为false,其他都为true
1-5 number转string
String();
toString();
+””;