Boolean(value) 是把值轉換成Boolean類型 example var b1 = Boolean("");//返回false,空字元串 var b2 = Boolean("s");//返回true,非空字元串 var b3 = Boolean(0);//返回false,數字0 var ...
Boolean(value) 是把值轉換成Boolean類型
example
var b1 = Boolean("");//返回false,空字元串
var b2 = Boolean("s");//返回true,非空字元串
var b3 = Boolean(0);//返回false,數字0
var b4 = Boolean(1);//返回true,非0數字
var b5 = Boolean(-1);//返回true,非0數字
var b6 = Boolean(null);//返回false
var b7 = Boolean(undefined);//返回false
var b8 = Boolean(new Object());//返回true,對象
function test() {
alert(' emmm..');
}
console.log(typeof test);
console.log(Boolean(test));
typeof判斷test為function
Boolean轉換為true
function test(can) {
alert(' emmm..');
}
console.log(typeof test());
console.log(Boolean(test()));
typeof判斷test()方法為undefined
Boolean轉換為false