RT,或者可以提供更好的版本(允许依赖三方库
function version1(condition){
if(condition || condition === 0){
console.log('version1允许'+condition+'执行')
}else{
console.log('version1不允许'+condition+'执行')
}
}
function version2(condition){
if(condition !== null && condition !== undefined && condition !== ''){
console.log('version2允许'+condition+'执行')
}else{
console.log('version2不允许'+condition+'执行')
}
}
version1(null)
version1(undefined)
version1('')
version1(0)
version1('anything')
console.log('============')
version2(null)
version2(undefined)
version2('')
version2(0)
version2('anything')