我们使用外部API,当Javascript似乎找到两者相等时,返回''或布尔值false。 例如:''等于false?区分''和布尔错误的最安全的方法是什么?
var x = '';
if (!x) {
alert(x); // the alert box is shown - empty
}
if (x=='') {
alert(x); // the alert box is shown here too - empty
}
var z = false;
if (!z) {
alert(z); // the alert box is shown - displays 'false'
}
if (z=='') {
alert(z); // the alert box is shown here too - displays 'false'
}
我们如何区分这两个?
正如您所提到的那样,之前已经提到过。为什么再提一次? – 2009-09-23 13:57:55
因为当时我发布这个,他没有提及它检查值AND类型... – NDM 2009-09-23 14:14:01