typeof检测数据类型 1.转换为字符串型 方式说明toString()转成字符串 var num=1;alert(num.toString());String()强制转换转成字符串 var num=1;alert(String(num));加号拼接字符串和字符串拼接的结果都是字符串 var num=1;alert(num+“我是字符串”); 2.转换为数字型 方式说明parselnt(string)函数将string类型转成整数数值型 parselnt(‘78’)parseFloat(string)函数将string类型转成浮点数数值型 parseFloat(‘78.21’)Number()强制转换函数将string类型转换为数值型 Number(‘12’)js隐式转换(- * /)利用算术运算隐式转换为数值型 ‘12’-0 3.转换为布尔型 方式说明Boolean()函数其他类型转成布尔值 Boolean(‘true’) 代表空、否定的值会被转换为false,如’ '、0、NaN、null、undefined其余的值都会被转换为true console.log(Boolean('')); //false console.log(Boolean(0)); //false console.log(Boolean(NaN)); //false console.log(Boolean(null)); //false console.log(Boolean(undefined)); //false console.log(Boolean('小白')); //true console.log(Boolean(12)); //true