1.括号内的表达式,会被强制转换为布尔类型

习题
if ("hello"){
console.log("hello")
}
//根据上面规则中 string 的规定,
//推断 if 为 true, 输出"hello".
if (""){
console.log("empty")
}
//根据规则-string,此为空字符串,
//推断 if 为 false, 不输出
if (" "){
console.log("blank")
}
//此为空白字符串,并非空字符串,
//本质上字符串里还是有东西的,
//所以为 true, 输出"blank"
if ([0]){
console.log("array")
}
//此为数组,即对象(object),为 true
if ('0.00'){
console.log("hahaha")
}
//此为 number ,为 true.
//注意规则中提到的+0和-0,是 false
网友评论