//其它类型转数字类型:三种方式
//1.parseInt(); 转整数
console.log(parseInt("10")); //10
console.log(parseInt("10abs")); //10
console.log(parseInt("g10")); //NaN
console.log(parseInt("10.98")); //10
console.log(parseInt("1fsd0")); //1
//2.parseFloat(); 转小数
console.log(parseFloat("10")); //10
console.log(parseFloat("10abs")); //10
console.log(parseFloat("g10")); //NaN
console.log(parseFloat("10.98")); //10.98
console.log(parseFloat("10.98gcfvf")); //10.98
console.log(parseFloat("1fsd0")); //1
//3:Number(); 转数字
console.log(Number("10")); //10
console.log(Number("10abs")); //NaN
console.log(Number("g10")); //NaN
console.log(Number("10.98")); //10.98
console.log(Number("10.98gcfvf")); //NaN
console.log(Number("1fsd0")); //NaN
/*总结:想要转整数用parseInt(),想要转小数用parseFloat()
想要转数字用Number(),但比上面两种方式严格*/
//其它类型转字符串类型
//1. .toString()
var num=10;
console.log(num.toString());
//2. String()
var num1=20;
console.log(String(num1));
//如果变量有意义,调用.toString()转换(这个用的多一些)
//如果变量没有意义,调用String()转换
var num3; //num3没有意义,不能使用.toString()转换
console.log(String(num3));
var num4=Null; ////num4没有意义,不能使用.toString()转换
console.log(String(num4));
//其它类型转布尔类型
//1. Boolean(值) 0 、空字符串、 null 、undefined、 NaN 会转换成false 其它都会转换成true
console.log(Boolean(1)); //true
console.log(Boolean(0)); //false
console.log(Boolean(11)); //true
console.log(Boolean(-10)); //true
console.log(Boolean("哈哈")); //true
console.log(Boolean("")); //false
console.log(Boolean(null)); //false
console.log(Boolean(undefined)); //false