1-1.字符串转number

函数 number();

  1. var str = "12";
  2. console.log(Number(str)) //12
  3. var s = "";
  4. var p = " ";
  5. console.log(Number(s))
  6. console.log(Number(p))

srring转number

parseInt() 转为int型
parsefloat() 转为小数型
  1. string-->number
  2. parseInt(); "12px";
  3. parseFloat(); "12.434px";
  4. 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();
+””;