目前在别人代码里,只看过以下这种应用,还有更多的应用示例吗?MDN:&&操作符的短路操作
//执行回调(&&的短路操作可作为类型检查)
typeof callback === 'function' && callback();
目前在别人代码里,只看过以下这种应用,还有更多的应用示例吗?MDN:&&操作符的短路操作
//执行回调(&&的短路操作可作为类型检查)
typeof callback === 'function' && callback();
check to avoid "property of undefined" ex:
if(req&&req.query&&req.query.id){
// do something with req.query.id.
}
The example you given is also a check: it wants to make sure the callback is a function and then use it.
13 回答12.8k 阅读
7 回答1.9k 阅读
3 回答1.1k 阅读✓ 已解决
2 回答1.2k 阅读✓ 已解决
6 回答853 阅读✓ 已解决
6 回答1k 阅读
2 回答1.3k 阅读✓ 已解决