转载:https://blog.csdn.net/baidu_37379451/article/details/82380836
let a = undefined;
let b = null;
let c = '';
let d = 0;
let e = {};
let f = [];
if (a) {
console.log("undefined 能过");
} else {
console.log("undefined 不能过");
}
if (b) {
console.log("null 能过");
} else {
console.log("null 不能过");
}
if (c) {
console.log(" '' 能过");
} else {
console.log(" '' 不能过");
}
if (d) {
console.log("0 能过");
} else {
console.log("0 不能过");
}
if (e) {
console.log("{} 能过");
} else {
console.log("{} 不能过");
}
if (f) {
console.log("[] 能过");
} else {
console.log("[] 不能过");
}
结果:
[2018-09-04 11:21:51.835] [INFO] console - undefined 不能过
[2018-09-04 11:21:51.836] [INFO] console - null 不能过
[2018-09-04 11:21:51.837] [INFO] console - '' 不能过
[2018-09-04 11:21:51.838] [INFO] console - 0 不能过
[2018-09-04 11:21:51.844] [INFO] console - {} 能过
[2018-09-04 11:21:51.849] [INFO] console - [] 能过