强制转换
1. any-number
1-1 字符转number
var str="12";
console.log(Number(str)) //12
var s = "";
var p = "";
console.log(Number(s))
console.log(Number(p))
string-->number
parsenInt(); "12px";
parseFloat(); "12.434px";
console.log(Number("12px") //NaN
1-2 boolean—>number
Number(true) //1
Number(false) //0
2.any—>boolean
2-1 number—>boolean
tips:0转换为false,其他都为ture
2-2 string—>boolean
tips:""为flase,其他为true
3 any-string
String();
toString();
+"";
自动转换
+,-,*,/,%
a.先将两边(Number)的值转换为number在计算
b.+只要有一边为字符串,那么结果一定是字符串
c.NaN和任何值计算,结果一定是NaN
练习题
b=14 c=100 d=NaN f= 10 g=90