1.逻辑与运算符
bad:
if(isShow){
// todo
}
good:
isShow&&toDo()
2.使用 includes 处理多重条件
if( currentWind === 2 || code === 3 || code === 4 ){
// toDo
}
可以改成
if([2,3,4].includes(currentWind)){
// todo
}
3.使用三元运算
待续
本文分享了三种提升代码效率的技巧:运用逻辑与运算符简化条件判断、使用includes方法处理多重条件判断以及采用三元运算符增强代码的简洁性和可读性。
1.逻辑与运算符
bad:
if(isShow){
// todo
}
good:
isShow&&toDo()
2.使用 includes 处理多重条件
if( currentWind === 2 || code === 3 || code === 4 ){
// toDo
}
可以改成
if([2,3,4].includes(currentWind)){
// todo
}
3.使用三元运算
待续
245
598

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