强制类型转换(二)
1.1 Boolean(): 将其他类型转为布尔类型
注意:除了0 "" '' undefined NaN null 得到fasle , 其他的都是true
1.2 String(): 将其他类型转为字符串类型
代码示例
//Boolean()
var a = "";
a = Boolean(a);
console.log(a,typeof a);//false "boolean"
var a = undefined;
a = Boolean(a);
console.log(a,typeof a);//false "boolean"
var a = null;
a = Boolean(a);
console.log(a,typeof a);//false "boolean"
var a = NaN;
a = Boolean(a);
console.log(a,typeof a);//false "boolean"
var a = 0;
a = Boolean(a);
console.log(a,typeof a);//false "boolean"
//String()
var a = 34;
a = String(a);
console.log(a,typeof a); //34 string
console.log(34,typeof 34);//34 "number"