js 中&&的使用
时间:2021-08-08 11:02:41
收藏:0
阅读:32
遇到下列代码goHome && (await router.replace(PageEnum.BASE_HOME));
&&这个逻辑与的作用是,当goHome为true时,执行右边的代码,否则就不会执行右边的代码
async function f(flag=false){
flag && console.log(‘hi‘)
console.log(‘hello‘)
}(f());
上面的代码执行结果为:hello
当修改flag为true后:
async function f(flag=false){
flag && console.log(‘hi‘)
console.log(‘hello‘)
}(f(true));执行结果为:hi hello
原文:https://www.cnblogs.com/baiyifengyun/p/15113745.html
评论(0)