在js里总遇到判断传参是否为空的情况,但是js里面通过obj==null判断好像作用不明显,
不过通过“!”判断,事半功倍。做个小计
function replace_null(str){
if(!str){
//alert('null');
document.write('0');
}else{
document.write(str);
}
}
本文介绍了一种在JavaScript中检查变量是否为空的有效方法。通过使用逻辑非运算符(!)来简化null或undefined值的判断过程。这比传统的obj==null方式更为高效。
在js里总遇到判断传参是否为空的情况,但是js里面通过obj==null判断好像作用不明显,
不过通过“!”判断,事半功倍。做个小计
function replace_null(str){
if(!str){
//alert('null');
document.write('0');
}else{
document.write(str);
}
}
2634
1059
4621

被折叠的 条评论
为什么被折叠?