functionfirst(){let a = "2";
let b = a - 1;
let c = a - "1";
let d = a - '';
let e = +a;
console.log(typeof b);//结果为:number
console.log(typeof c);//结果为:number
console.log(typeof d);//结果为:number
console.log(typeof e);//结果为:number
}
(2)
functionsecond(){let a = 3;
let b = a + '';
let c = a + 'foo';
console.log(typeof b);//结果为:string
console.log(typeof c);//结果为:string
}
值得注意的是:object类型转换为boolean型
functionthird(){let a = newBoolean(false);
if(a){
console.log("T");
}else{
console.log("F");
}
//结果为:Tlet b = newBoolean(0);
if(b){
console.log("T");
}else{
console.log("F");
}
//结果为:T
}